•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 363,779 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,548 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser:
Given the date in mm-dd-yyyy (or M-D-YYYY) format (or any combination of that format) you can find out what day of the week that was on or is on or will be on, within the limitations of the system the script resides on.
This snippet uses only core functions and modules so nothing needs to be installed but it is worth mentioning that there are numerous date modules on CPAN that offer a wide range of functions for handling date calculations.
http://search.cpan.org/search?query=date&mode=all
This snippet assumes the date is in mm-dd-yyyy format but can easily be adapted to handle any combination of those date parameters. Can also handle years in three digit and two digit format but see the Time::Local and localtime() documentation for limitations.
This snippet uses only core functions and modules so nothing needs to be installed but it is worth mentioning that there are numerous date modules on CPAN that offer a wide range of functions for handling date calculations.
http://search.cpan.org/search?query=date&mode=all
This snippet assumes the date is in mm-dd-yyyy format but can easily be adapted to handle any combination of those date parameters. Can also handle years in three digit and two digit format but see the Time::Local and localtime() documentation for limitations.
Last edited : Oct 13th, 2006.
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]; }
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)