From an answer I just posted in alt.perl. How to get the day of the week for a given date, both as a number, and as an abbreviation. Works for 1970 to 2038.
use Time::Local; my ($year, $month, $day) = qw(2002 02 21); my $gmtime = timegm(0,0,0,$day,$month-1,$year-1900); my @gmtime = gmtime($gmtime); # convert back print "day of week is $gmtime[6]\n"; # sunday = 0, saturday = 6 my ($day_of_week) = gmtime($gmtime) =~ /^(\S+)/; # fetch first wor +d print "day of week is $day_of_week\n"; # "Sun" .. "Sat"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Day of week for an arbitary date using core modules
by blakem (Monsignor) on Feb 21, 2002 at 20:20 UTC | |
by davorg (Chancellor) on Feb 22, 2002 at 07:22 UTC | |
Re: •Day of week for an arbitary date using core modules
by YuckFoo (Abbot) on Feb 22, 2002 at 17:29 UTC | |
Re: •Day of week for an arbitary date using core modules
by meonkeys (Chaplain) on Apr 28, 2002 at 05:51 UTC |
Back to
Cool Uses for Perl