
KevinR
Veteran

Feb 5, 2008, 1:08 PM
Post #2 of 3
(1404 views)
|
Re: [rajiv_chennai] Help on get day name for a given date
[In reply to]
|
Can't Post
|
|
Normally I don't just post code for people, but I had this snippet posted on another forum so I will post it here:
use Time::Local 'timelocal_nocheck'; # An array to hold the names of each day of the week. my @weekday = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); # '09-11-2001' can be a parameter/argument you pass to the script my $mm_dd_yyyy = '09-11-2001'; my $day_of_week = get_day($mm_dd_yyyy); print "$mm_dd_yyyy was a $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]; } Next time I would prefer to help you with your existing code. -------------------------------------------------
|