Try the Date::Calc module. It has tons of handy date functions. Example:
use Date::Calc qw(Decode_Date_US Day_of_Week Day_of_Week_to_Text);
my $text = '07/25/01';
#if validity of date is in question
my @date = Decode_Date_US($text);
print ((@date ? Day_of_Week_to_Text(Day_of_Week(@date)) : "not a valid
date") . "\n");
#if the date will always be valid
print Day_of_Week_to_Text(Day_of_Week(Decode_Date_US($text))) . "\n";
-----Original Message-----
From: Wagner-David [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 25, 2001 10:10 PM
To: [EMAIL PROTECTED]
Subject: RE: Convert date mmddyy to day of the week
Here is a shot.
Take the date in splitting on 2 digits and / if there
Print number of items in array
Setup a Days array
Use timelocal at noon to get total seconds
Run seconds thru localtime (array defs are commented
print out the date in format mm/dd/yyyy, day of week number and day
of the week
Wags ;)
============================================================================
=====================
#!perl -ws
use Time::Local;
my $Dates = '07/25/01';
my @DateUse = ();
while ( $Dates =~ /(\d{2}){1}\/*/g ) {
printf "%-s\n",$1;
push(@DateUse,$1);
}
printf "%d\n", scalar(@DateUse);
my @Days = qw(Dummy Monday Tuesday Wednesday Thursday Friday Saturday
Sunday);
if ( ! (scalar(@DateUse) and ! (scalar(@DateUse) % 3) ) ) {
die "Expecting groups of 3 for date calculations:$!";
}
for(my $MyId=0;$MyId<scalar(@DateUse);$MyId+=6) {
my $t1 =
timelocal(0,0,12,$DateUse[$MyId+1],$DateUse[$MyId]-1,$DateUse[$MyId+2]);
printf "t1: %9d\n", $t1,;
my $MyTime1 = localtime($t1);
printf "LocalTime1: %-s\n", $MyTime1;
my @MyTimeInfo = localtime($t1);
# MyTimeInfo [0] = Seconds
# [1] = Minutes
# [2] = Hours
# [3] = Day of month
# [4] = Month minus 1
# [5] = Year (from 1900)
# [6] = Day of Week(Mon=1 thru Sun=7);
# [7] = Day of year
# [8] = Day light Savings(0: off 1: On)
#
printf "%02d/%02d/%04d -> %d ->%-s\n", $MyTimeInfo[4]+1, $MyTimeInfo[3],
(1900+$MyTimeInfo[5]), $MyTimeInfo[6], $Days[$MyTimeInfo[6]];
}
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 25, 2001 13:33
To: [EMAIL PROTECTED]
Subject: Convert date mmddyy to day of the week
I want to convert a date in the format mm/dd/yy to the day of the week. For
example 07/25/01 should become Wednesday.
Thanks
John
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]