On Mon, 08 Apr 2002 02:04:10 +0100, Troy May wrote:
> What's the easiest way to get yesterday's date from localtime? I need
> it in this format: (for today) "070402".
>
> Here is the code used for today's date:
>
> ($sec,$min,$hour,$mday,$mon,$year,undef,undef,undef) = localtime();
> $mon++;
> $year %= 100;
> $theDate = sprintf("%02u%02u%02u", $mday, $mon, $year);
>
> Thanks.
($sec,$min,$hour,$mday,$mon,$year,undef,undef,undef)
= localtime(time -86_400); # seconds in 24 hours
$mon++;
$year %= 100;
$theDate = sprintf("%02u%02u%02u", $mday, $mon, $year);
But you can simplify that:
($mday, $mon, $year) = (localtime(time - 86_400))[3 .. 5];
$mon++;
$year %= 100;
$theDate = sprintf("%02u%02u%02u", $mday, $mon, $year);
Or even just:
use POSIX 'strftime';
$theDate = strftime('%d%m%y', localtime(time - 86_400);
hth,
Dave...
--
Don't dream it... be it
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]