Article 3324 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:3324
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!news.ecn.bgu.edu!wupost!howland.reston.ans.net!spool.mu.edu!olivea!apple.com!voder!berlioz.nsc.com!jedi!arielf
From: arielf@mirage.nsc.com (Ariel Faigon)
Subject: Re: day of the week from date?
Message-ID: <1993Jun10.211104.8374@berlioz.nsc.com>
Followup-To: comp.lang.perl
Summary: Zeller congruence in perl (repost)
Keywords: day-of-week, perl
Sender: news@berlioz.nsc.com (UseNet News account)
Reply-To: arielf@mirage.nsc.com
Organization: National Semiconductor Corp.
References: <130424@netnews.upenn.edu>
Date: Thu, 10 Jun 1993 21:11:04 GMT
Lines: 48


Iau@desci.wharton.upenn.edu (Yan K. Lau) just wrote:
: How can I figure out which day of the week it is (e.g. Wed) from a date
: (not necessarily today) in day month year format (e.g. 9 Jun 93)?  Is this easy to do?

Here is a script posted by Carl Rigley to this newsgroup (almost three years ago. Wow).
which does this efficiently.
So the answer to this question is: Yes it is easy if you've read this newsgroup
since it was established or know how to search in the archives :-)

#!/usr/local/bin/perl
# From: cdr@brahms.amd.com (Carl Rigney)
# Summary: zeller's congruence
# Keywords: weekday perl subroutine
# Date: 2 Oct 90 17:21:14 GMT
# Organization: Advanced Micro Devices; Sunnyvale, CA
# 
# Here's a simple subroutine to calculate Day of the Week using
# Zeller's Congruence, which I've found very useful.  A lot of
# the temporary variables could be omitted by making it harder to read.
 
# usage: zeller yyyy mm dd
unless ($#ARGV == 2) {
    print STDERR "Usage: $0 yyyy mm dd\n";
    exit 1;
}
$day = &weekday(@ARGV);
print $day,"\n";
 
sub weekday {
        local($year,$month,$day)=@_;
        local($y,$m,$c,$yy,$z);
 
        local(@wday) = ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" );
 
        $y = $year;
        $m = ($month + 10) % 12;
        $y-- if ($m > 10);
        $c = int ( $y / 100 );
        $yy = $year % 100;
 
        $z = ( int ( (26*$m - 2)/10) + $day + $yy + int($yy/4) + int ($c/4) - 2*
$c ) % 7;
        return $wday[$z];
}

---
Ariel Faigon	arielf@mirage.nsc.com


