[lug] Perl days/dates

Evelyn Mitchell efm at tummy.com
Tue Nov 14 17:04:01 MST 2000


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




More information about the LUG mailing list