in reply to Finding the Day of Week in Windows

I know its not what you asked for .. you're looking at localtime methods, but I'll contribute the following just for interests sake:

This method will take a day, month and year and tell you what day of the week it was/is/will be.

I know this doesn't make sense to the human eye, but believe me, its an official algorithm for calculating the day of the week. I've just taken the algorithm and turned it into a perl version. If you want more info, search google for something like http://www.google.com/search?q=calculate+the+day+of+the+week

sub dow { ($year, $month, $day) = @_; $year-- if $month < 3; return ($year+int($year/4)-int($year/100)+int($year/400)+((0,3,2,5 +,0,3,5,1,4,6,2,4)[$month-1])+$day) % 7; } print (('Sun','Mon','Tues','Wed','Thu','Fri','Sat')[dow(2002,07,12)]);
As with localtime, the algorithm returns a number that relates to the day of the week. By using the return as the index to an anonymous array, we get the actual day.

Replies are listed 'Best First'.
Re: Re: Finding the Day of Week in Windows
by osama (Scribe) on Jan 07, 2003 at 05:10 UTC
    This algorithm is perfect for programs in other languages, but not in Perl... Why use something like this at all when there are so many builtins that do the job???
      Name one that doesn't require any modules. And I mean any modules. Including POSIX. Sure, I know that they all come with perl but why open yet-another file when if all you want from it is to compute the day of the week for a particular date?