It’s easier than you might think to calculate the day of the week for a date from September 14th, 1752 (the day the Gregorian calendar was made official in America and England) to the indefinite future.
The days of the week are numbered as follows:
Sunday 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday 0
For each month there is a key value:
January 3 February 6 March 6 April 2 May 4 June 0 July 2 August 5 September 1 October 3 November 6 December 1
And finally, the century values:
1700's 2 1800's 0 1900's 5 2000's 4 2100's 2
Now you will be keeping a running total of a series of numbers. First, take the last two digits of the year as your initial number. Divide that number by 4 and discard the remainder. Add the result to your initial number. Then add the century value. Next add the key value for the month in question. Then add the day of the month. Now divide the grand total by 7. The remainder is all that counts.
Suppose we want to know what day of the week December 25th, 2006 is.
Last two digits of year: 6
Divided by 4 (discarding remainder): 1
Century Value: 4
Key Value for December: 1
Day of Month: 25
37 / 7 = 5 with a remainder of 2 so our answer is Monday.
- All we are concerned with is the remainder after dividing the total by 7. Since we’re adding a sum of numbers, we never have to add a number greater than 6. Any time we are adding a number, we can subtract the largest multiple of 7 that is not greater than that number. And any time our running total reaches a number greater than 6, we can again subtract the largest multiple of 7 that is not greater than our running total. Knowing the multiples of 7 up to 98 will greatly improve your speed.
- The next shortcut is obvious, but practical. I typically calculate days of the week for the current year (and often for the next year). I do this often enough that I unintentionally memorize the first three steps. The first three steps are year-specific. If you cache the result of the first three steps, you’ll never have to do the math for that year again. For 2006, the result is 4 (see the first three steps of example #1). So in practice, if I wanted to know the day of the week that Christmas falls on this year I wouldn’t have to do any math for the first bit. I’d just start my running total with 4, then add 1 and 4 to get a final result of 2. Christmas this year falls on a Monday.
Example #2 (using first shortcut):
May 17, 1999
Last two digits of year: 1 (98 is a multiple of 7, so we subtract it from 99)
Divide year by 4 (discarding remainder): 3 (99 / 4 is 25 but 21 is a multiple of 7 so we subtract it from 25)
Century Value: 5
Our running total is now 9 which is 2 more than a multiple of 7,
so we’ll just use that as our running total: 2
Key Value for May: 4
Day of Month: 3 (14 is a multiple of 7, so we’ll subtract that from 17)
7 / 7 = 1 with a remainder of 2 so the answer is Monday.
A note about Leap Years:
If the last two digits of a year are divisible by 4 with no remainder, they are a leap year, and you must subtract 1 from the key values for January and February. Other months are unaffected. Years ending in 00 (the last year in a century*) such as 1800, 1900, and 2000 must be divisible by 400 in order to be a leap year. Thus 1800 and 1900 are not leap years, while 2000 is. Even though such years are the last year in a century technically, for our purposes we are not dealing with centuries, but rather with sets of 100’s such as the 1800’s and the 1900’s. Therefore 1900 should be treated as an ordinary year (not a leap year) in the 1900’s.