[comp.lang.c] general routine for calendar application...

jman@ICS.UCI.EDU (Jimmy MAN) (05/28/90)

    Is there anybody in the net who might have a routine for calculating
the day of the week given an arbitrary date. I believe the algorithm will
be an implementation of something called Julian Calendar (???).
I'd appreciate if someone out there send me the algorithm via
E-mail or eventually post it on the bbc... In advance, thank you!

                                    Jimmy Man.

steve@taumet.COM (Stephen Clamage) (05/28/90)

In article <9270.643838242@ics.uci.edu> jman@ICS.UCI.EDU writes:
>
>Is there anybody in the net who might have a routine for calculating
>the day of the week given an arbitrary date.

Here is an algorithm known as Zeller's congruence.  It may be of
general interest, so I am posting it.  I found it in a magazine (I
forget which one) a few years ago.

The day of the week (0 = Sunday) is given by
  W = ((26*M - 2) / 10 + D + Y + Y/4 + C/4 - 2*C) % 7
  where
	C is the century
	Y is the last two digits of the year
	D is the day of the month
	M is a special month number, where Jan and Feb are taken as
	  month 11 and 12 of the previous year

Each division is truncating division, and the terms cannot be combined.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com