CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Help on get day name for a given date

 



rajiv_chennai
Novice

Feb 5, 2008, 1:37 AM

Post #1 of 3 (966 views)
Help on get day name for a given date Can't Post

Hi to all,

I want to know how do i get a day name for a given date.

Is Any Idea Please.

Thanks

RajivGandhi.


KevinR
Veteran


Feb 5, 2008, 1:08 PM

Post #2 of 3 (955 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:


Code
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.
-------------------------------------------------


rajiv_chennai
Novice

Feb 6, 2008, 3:58 AM

Post #3 of 3 (943 views)
Re: [KevinR] Help on get day name for a given date [In reply to] Can't Post

Its working fine.
Thank U.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives