[comp.sys.ibm.pc] Calendar calculations

spector@suvax1.UUCP (Mitchell Spector) (01/25/88)

In article <485@psu-cs.UUCP>, winterss@psu-cs.UUCP (Stafford Winters ) writes:
> I would like to know the formula for calculating the day of the week for any
> given date.  I have seen it once before, but I didn't write it down.  Having
> 
> Tad Winters

   Here's a formula given in the book An Introduction to the Theory of Numbers,
by Niven and Zuckerman.

   Let M be the number of the month, defined so that Jan = 11, Feb = 12,
Mar = 1, Apr = 2, ..., Dec = 10.  Let N be the number of the day within the
month.  Let C be the hundreds in the year, and let Y be the rest of the year.
Let L be 1 for a leap year and 0 for a non-leap year.

The formula

(N + [2.6M - 0.2] + Y + [Y / 4] + [C / 4] - 2C - (1 + L)[M / 11]) mod 7

yields 0 for Sunday, 1 for Monday, ..., 6 for Saturday.

(Square brackets denote the greatest integer function.)

-- 
Mitchell Spector                                        |"Give me a
Dept. of Computer Science & Software Eng., Seattle Univ.|     ticket to
Path:    ...!uw-beaver!uw-entropy!dataio!suvax1!spector |             Mars!!"
  or:   dataio!suvax1!spector@entropy.ms.washington.edu | -- Zippy the Pinhead