Quickly calculate the day of the week for any date of the Gregorian calendar—useful for scheduling appointments and meetings!
The imperfect Gregorian calendar, when combined with the imperfect Earth year—which is an even multiple of neither 12 (the number of months) nor 7 (the number of days in the week), but instead an icky 365.24237404 days long (approximately!)—means that, for most of us to find what day of the week a meeting falls on, we have to consult a wall calendar or our PDA.
But what if you had your own perpetual calendar in your head? What if you could, with practice, take just a few seconds to calculate any day of the week from centuries ago and into the distant future, when they finally nudge the Earth into a more reasonable orbit?
You can. Here's how.1,2
To calculate any weekday, you basically need to find four numbers, add them together, and then cast out sevens (i.e., calculate that number modulo 7, a simple procedure). In practice, you can do the modulo math as you go along to keep the numbers small and simply keep a running total.
Here are the numbers you need:
The year-item
The month-item
The day-item
Adjustment
Finding the year-item (or key number for the year) is easy. Here's the formula:
(YY + (YY div 4)) mod 7
where YY
represents the
last two digits of the year.
Finding the month-item requires some memorization. There are only 12 key numbers, though, one for each month, as shown in Table 4-10.
Table 4-10. Key numbers for calendar months
Month | Key number |
---|---|
January | 0 |
February | 3 |
March | 3 |
April | 6 |
May | 1 |
June | 4 |
July | 6 |
August | 2 |
September | 5 |
October | 0 |
November | 3 |
December | 5 |
To memorize these numbers, you can use any mnemonics that you prefer, such as the Dominic System [Hack #6].
The day-item is simply the day of the month—for example,
1
for April 1, 31
for October 31, 15
for March 15, and so on.
The fourth number you will need to find is an adjustment to the total. It has two parts: the century-item, plus a possible tweak if the year is a leap year.
Since you'll mostly be finding dates in the 20th and 21st centuries, you can probably ignore most of Table 4-11, and just remember that for dates from 1900–1999, the adjustment is 0 (that is, don't add anything), and for dates from 2000–2099, you add 6.
A more precise method follows.
The Julian calendar ended in most Western countries on September 2, 1752, and the Gregorian calendar began on September 14, 1752.
Tip
They had to fudge the date when they converted over. Legend has it that people rioted for their lost days. And you thought Y2K was a big deal.
To get the century-item for any date on the Julian calendar, subtract the century (which would be 14 for the year 1492) from 18, and cast out sevens.
To get the century-item for any Gregorian year up to 9999, take the first two digits of the year, cast out fours, subtract the result from 3, and multiply the difference by 2. Thus, for the year 2008:
20 mod 4 = 0 3 - 0 = 3 3 × 2 = 6
And 6 is indeed the century-item for the 2000s, as shown in Table 4-11.
Now for the leap-year tweak. If your date is in January or February of a leap year, subtract 1 from the running total.
Any year evenly divisible by 4 in the Gregorian calendar is a leap year, except that years also divisible by 100 aren't—except that years also divisible by 400 are leap years. Thus, 1936 was a leap year (it is evenly divisible by 4); 1937 was not a leap year (it's not divisible by 4). The years 1800 and 1900 weren't leap years (they're evenly divisible by 100), but 2000 was (it's also evenly divisible by 400).
Leap years in the Julian calendar are simply any year divisible by 4.
If you have cast out all sevens (that is,
calculated the number mod
7
correctly), the end result will
be a number from 0 to 6. This number will tell you the weekday,
starting with Sunday at 0 and counting upward, as shown in Table 4-12.
Let's calculate the weekday of the first moonwalk, July 21, 1969:
The key number for the year is
(69
+
(69
div
4))
mod
7
.69
div
4
=
17
, because69
/
4
=
17
with a remainder of 1 (or17r1
).69
+
17
=
86
.Now, cast out sevens:
86 mod 7 = 2
, because the next highest multiple of 7 is 84, and86
–
84 = 2
. Remember the number 2.The key number for the month of July is 6 (see Table 4-10). Add that key number to the result you remembered in the previous step:
6
+
2
=
8
.Cast out sevens:
8
mod
7
=
1
. (7 goes into 8 once, with 1 left over.) Remember the number 1.The key number for the day is 21, because the first moonwalk took place on July 21. Add the result you remembered in the previous step:
2
1+
1
=
22
.Cast out sevens:
22
mod
7
=
1
.The adjustment is 0, because this took place from 1900–1999 and it was not January or February of a leap year:
1
+
0
=
1
.The final result is
1
, so the first moonwalk took place on a Monday. (And consulting a calendar, we find that this is true!)
To be precise, the moonwalk took place at 2:39:33 A.M. UTC, which was Sunday night throughout the U.S. I bet the workers of the world had quite a bit to talk about around the water cooler the next day.
Carroll, Lewis. "Lewis Carroll's Algorithm for finding the day of the week for any given date." http://www.cs.usyd.edu.au/~kev/pp/TUTORIALS/1b/carroll.html.
Mentat Wiki. "Calendar Feat." http://www.ludism.org/mentat/Calendar Feat (explains several different ways to calculate the date, and many shortcuts).
"Use the Dominic System" [Hack #6] uses memorization of the month-item table as an example.
If the World Calendar were adopted, the same date would always have the same weekday in every year. Simple, flexible, logical, and utterly unlikely to be adopted, it's the Esperanto [Hack #51] of calendars! (See http://personal.ecu.edu/mccartyr/world-calendar.html.)
Get Mind Performance Hacks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.