[lug] Perl days/dates

Atkinson, Chip CAtkinson at Circadence.com
Tue Nov 14 17:17:02 MST 2000


I'm not quite sure what you are saying.  The function localtime() returns an
array of 9 items, sec, min, hr, mday, mon, year, weekday, yearday, and
isdaylightsavtime.  $datestuff[6] is the weekday, which is what I'm looking
at.
The odd thing is that $datestuff[6] has a value of 1 for the 4th of this
month.

I started out with the names of the days starting at "Sun", but they were
off by two so I adjusted the days array to make it work.


Chip
> -----Original Message-----
> From: Evelyn Mitchell [mailto:efm at tummy.com]
> Sent: Tuesday, November 14, 2000 5:04 PM
> To: lug at lug.boulder.co.us
> Subject: Re: [lug] Perl days/dates
> 
> 
> Did you choose to have the names of the days start with Friday?
> There isn't anything in this script which ties the array index
> to a system function. You have hardcoded the index as 6 (Wednesday).
> If you were to choose to start the week on Sunday, you would
> have to change the index as well.
> 
> Evelyn Mitchell
> efm at tummy.com
> 
> On Tue, Nov 14, 2000 at 04:55:40PM -0700, Atkinson, Chip wrote:
> > Greetings,
> > 
> > I'm writing a perl script to figure out the day of the week 
> based on a given
> > date.  The numeric value for the day of the week seems 
> rather odd in that
> > the week starts with Friday.  Does anyone know about this?  
> Here's the
> > script in its entirety.
> > 
> > Chip
> > 
> > #!/usr/bin/perl
> > 
> > $| = 1;
> > use strict;
> > use Time::Local;
> > 
> > use vars qw (@months @days $i);
> > use vars qw ($sec $min $hours $mday $mon $year);
> > use vars qw ($TIME $WEEKDAY @datestuff);
> > 
> > @months = ("January",
> >            "February",
> >            "March",
> >            "April",
> >            "May",
> >            "June",
> >            "July",
> >            "August",
> >            "September",
> >            "October",
> >            "November",
> >            "December");
> > 
> > @days = ("Fri",
> >          "Sat",
> >          "Sun",
> >          "Mon",
> >          "Tue",
> >          "Wed",
> >          "Thu",
> >          "Fri",
> >          "Sat");
> > 
> > 
> > 
> > $year = 2000;
> > $mon  = 11;
> > $mday  = 4;
> > for ($mday = 1; $mday < 11; $mday++)
> > {
> >   $TIME = timelocal (1, 1, 1, $mday, $mon, $year);
> >    print ("\nYear: $year, Month: $mon, Day: $mday");
> > 
> >    @datestuff = localtime ($TIME);
> >    print (" Mon: $datestuff[4]");
> >    print (" Year: ", $datestuff[5] + 1900);
> >    print (" Wday: ", $days[$datestuff[6]], "\n");
> > }
> > 
> > _______________________________________________
> > Web Page:  http://lug.boulder.co.us
> > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> 
> -- 
> http://www.tummy.com/ Consulting and Software for Linux and Unix
> KRUD - Kevin's Red Hat Uber Distribution - the Freshest Red 
> Hat every month
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> 




More information about the LUG mailing list