find day of given date in perl
by kalai[ Edit ] 2008-12-18 12:20:29
#!D:\Perl\bin\perl
use Time::Local 'timelocal_nocheck';
my @weekday = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
my $mm_dd_yyyy = '2008-12-16';
my $day_of_week = get_day($mm_dd_yyyy);
print "$day_of_week";
sub get_day {
my $date = shift || return(0);
my ($mon,$mday,$year) = $date =~ /(d+)-(d+)-(d+)/;
my $epochtime = timelocal_nocheck(0, 0, 0, $mday, $mon-1, $year);
my $day = (localtime($epochtime))[6];
return $weekday[$day];
}
RESULT:
Tuesday