Perpetual Calendar Formula

This is not exactly the method I use since I have memorized a table
that helps me with steps 1, 2, and 8, but this is close to my algorithm.

    1. Take the last two digits of the year.
    2. Divide by 4, discarding any fraction.
    3. Add the day of the month.
    4. Add the month's key value:
	1 for January
	4 for February
	4 for March
	0 for April
	2 for May
	5 for June
	0 for July
	3 for Aug
	6 for September
	1 for October
	4 for November
	6 for December
    5. Subtract 1 for January or February of a leap year.
    6. For a Gregorian date, add 0 for 1900's, 6 for 2000's, 4 for
       1700's, 2 for 1800's; for other years, add or subtract multiples
      of 400.
    7. For a Julian date, add 1 for 1700's, and 1 for every additional
       century you go back.  (Basically subtract the century from 18.)
    8. Add the last two digits of the year.
    9. Divide by 7 and take the remainder.

   Now 1 is Sunday, the first day of the week, 2 is Monday, and so on.

For example, suppose you want to know the day of the week of December
7, 1941.

Step 2 gives you 41/4 or 10
After step 3 has you add 7 to get 17
After step 4 adds 6 to get to 23
Steps 5-7 do nothing so you still have 23
Steps 8 adds 41 to get 64
Step 9 divides by 7 and the remainder is 1.  1 is Sunday.

Actually at each step you can divide by 7 taking the remainder and that
simplifies the calculation.

Step 2 gives you 41/4 or 10 which becomes 3
After step 3 has you add 7 which still leave you with 3
After step 4 adds 6 to get to 9 or 2
Steps 5-7 do nothing so you still have 2
Steps 8 adds 41 to get 43 or 1.  1 is Sunday.

If you are not sure whether December 7, 1941 is a Sunday or not, there
are problems with your education.  Let me tell you that it is.

To actually use my algoritm I replace steps 1, 2, and 8 with adding in
a value for the previous leap year, plus the number of years since the
previous leap year.  This table is

			0 for 00, 28, 56, or 84
			5 for 04, 32, 60, or 88
			3 for 08, 36, 64, or 92
			1 for 12, 40, 68, or 96
			6 for 16, 44, or 72
			4 for 20, 48, or 76
			2 for 24, 52, or 80


Hence for December 7, 1941.  One says that the last leap year was 1940
and it is one year later so you have 1+1 or 2.  December adds 6 (or
subtracts one, both are the same mod 7) so we have 1.  Then add 7 for
the 7th day of the month.  It does nothing, mod 7, so we end up with a
1, which is Sunday.

Try July 4, 1776.  

The 1700s have us start with a 4.  76 in the above table is a 4 and we
are talking 0 years after the leap year.  So the total so far is 8 mod
7 which is 1.  July adds 0, so we still have 1.  Add in the 4 for the
fourth day of the month and you have 5 or Thursday.

					Mark Leeper
					mark.leeper@lucent.com

    Source: geocities.com/markleeper