Ken Barker wrote:
> Try this:
>
> $now = time;
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($epoch);
> $mon = $mon += 1;
> $year = $year += 1900;
> $yesterday = sprintf("%02d%02d%04d",$mday,$mon,year);
I'm sure the reader could probably figure the typos, but just to be safe,
a couple of notes:
$epoch should be $now or vice versa (but it's easier to just remove $epoch
since it defaults to the output of time.
$mon = $mon +=1 is better written as $mon += 1;
$year = $year += 1900; is better written as $year += 1900;
Or shorten it up a couple of lines:
my ($mday, $mon, $year) = (localtime)[3,4,5];
my $yesterday = sprintf "%02d%02d%04d", $mday, $mon+1, year+1900;
And if you really wanted yesterday's date, you should have subtracted
a day off the epoch :
my ($mday, $mon, $year) = (localtime (time - 86400))[3,4,5];
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs