J
John
Given a date passed in from a spreadsheet, I'm trying to come up with
the day of the week.
Trying to use timelocal (http://search.cpan.org/~drolsky/Time-
Local-1.17/lib/Time/Local.pm) to turn the date into a scalar, then
localtime to return the full slate of results, including the day of
the week.
I seem to be getting back at least what I put in -- that is the month,
day and year are inverted, reverted and returned as I first called
timelocal. But the day of week is not matching my paper calendar.
#!/usr/bin/perl -w
use strict;
use Time::Local;
my $gdate;
my @wkdayname = ('Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday',
'Friday', 'Saturday', 'Sunday');
{
$gdate = "4/18/2007";
my ($gmonth, $gmday, $gyear);
($gmonth, $gmday, $gyear) = split(/\//,$gdate);
{
print "\ngmonth = $gmonth, ";
print "gmday = $gmday, ";
print "gyear = $gyear\n ";
}
my $gday;
my @timeScr;
my $scrTime=timelocal(0, 0, 11, $gmday, $gmonth, $gyear-1900);
@timeScr = localtime($scrTime);
print "timescr= @timeScr \n";
$gday = $timeScr[6];
print "using timescr6 gday = $gday\n";
$gday = $wkdayname[$gday];
print "gday = $gday\n";
}
Results:
gmonth = 4, gmday = 18, gyear = 2007
timescr= 0 0 11 18 4 107 5 137 1
using timescr6 gday = 5
gday = Friday
But it says here that April 18, 2007 is a Wednesday.
John Campbell
Haddonfield, NJ
Perldoc v3.09, under perl v5.008001 for darwin
the day of the week.
Trying to use timelocal (http://search.cpan.org/~drolsky/Time-
Local-1.17/lib/Time/Local.pm) to turn the date into a scalar, then
localtime to return the full slate of results, including the day of
the week.
I seem to be getting back at least what I put in -- that is the month,
day and year are inverted, reverted and returned as I first called
timelocal. But the day of week is not matching my paper calendar.
#!/usr/bin/perl -w
use strict;
use Time::Local;
my $gdate;
my @wkdayname = ('Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday',
'Friday', 'Saturday', 'Sunday');
{
$gdate = "4/18/2007";
my ($gmonth, $gmday, $gyear);
($gmonth, $gmday, $gyear) = split(/\//,$gdate);
{
print "\ngmonth = $gmonth, ";
print "gmday = $gmday, ";
print "gyear = $gyear\n ";
}
my $gday;
my @timeScr;
my $scrTime=timelocal(0, 0, 11, $gmday, $gmonth, $gyear-1900);
@timeScr = localtime($scrTime);
print "timescr= @timeScr \n";
$gday = $timeScr[6];
print "using timescr6 gday = $gday\n";
$gday = $wkdayname[$gday];
print "gday = $gday\n";
}
Results:
gmonth = 4, gmday = 18, gyear = 2007
timescr= 0 0 11 18 4 107 5 137 1
using timescr6 gday = 5
gday = Friday
But it says here that April 18, 2007 is a Wednesday.
John Campbell
Haddonfield, NJ
Perldoc v3.09, under perl v5.008001 for darwin