Eko Budiharto wrote:
> hi list,
> I have a question is there anyway that I can the date of sunday from
> this week and last week?
> I just confuse how to do it. I usually use time::format and time::local;
> For example, aug 13 is saturday it means aug 14 is sun and sunday last
> week is aug 7. how do I do the calculation?
use strict;
use warnings;
my $epoch = time; # get epoch for today
my @d = localtime $epoch; # break it into fields - you may want gmtime
instead of localtime
my $next_sunday;
my $prev_sunday;
if ($d[6] == 0) { # Sunday ?
# not sure what you want to do here
} else {
$next_sunday = (7 - $d[6]) * 86400 + $epoch;
$prev_sunday = $next_sunday - 86400 * 7;
}
print scalar localtime $next_sunday, "\n";
print scalar localtime $prev_sunday, "\n";
# you can drop the time portion and just format the date with POSIX::strftime
use POSIX;
print strftime "%A, %b %d %Y\n", localtime $next_sunday;
print strftime "%A, %b %d %Y\n", localtime $prev_sunday;
__END__
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs