A method for finding the day of the week for any date -- in your head.

Wednesday, December 2, 2009

Learn the First Sunday Doomsday Algorithm

[Revised 8/17/2011]
This longer article will show you how to determine the day of the week for any given date -- without consulting a calendar. It covers some history (of calendars and methods) and explains how this method works, and why it works.

If you’re like most people, you can’t imagine how you might figure out the days of some month in the past or future. If you were asked about a date in the current month, you could probably figure that out, using multiples of seven and a bit of finger counting. Some people are really good at this, and some can mentally picture the whole month’s calendar – a skill not required to learn this method.

People have struggled to compute days of the week ever since Julius Caesar decreed the modern calendar in 46 B.C. (and Pope Gregory finalized the leap year rules in 1582). Finally in 1882, Christian Zeller of Germany published a formula, which remains probably the best method for computer programs.

But can it be done mentally, by an average person? Yes! Charles Dodgson (using his famous pen name, Lewis Carroll) published a method in 1887, which mathematician John Horton Conway enhanced in a 1973 journal article (naming it the Doomsday algorithm), and a 1982 book. Since 1994 (the year of the first practical web browser), Rudy Limeback has provided a web site with an excellent explanation of Conway’s algorithm. Mike Walters suggested an improvement in 2008, in his blog, and enhanced it in 2010 in a paper with Chamberlain Fong. The First Sunday doomsday algorithm is built on these foundations.

The algorithm is a four-step process of simple mental arithmetic. A few memorable phrases will remind you of the four steps. The entire process is summarized in a handy reference chart, in the Summary section below. Some paragraphs, labeled “tech note”, give background material and history, not needed if you just want to use the method.

The big advantage of this method is that you can skip two, or three, of the four steps, when working with the current year, or month. Thus First Sunday doomsday algorithm is useful for real-life, near-term date questions, as well as the “parlor trick” of quickly naming the day of distant dates. The method works for dates all the way back to the year 1 AD.

How difficult is it?

The method presented here has been fine-tuned to use just one subtraction, and just one trivial division (of an even number by 2). The rest is addition – on average just three of them -- of small numbers. There is no “memory space” required to hold intermediate results; you just accumulate a running total. There will be, of course, inevitably some adding or subtracting of sevens in any calendar work.

The logical way to figure the day of the week, would be to count the days elapsed from some “zero day”, then divide by seven. The remainder would be your answer. In doing this count, you would have to account for all the rules of month lengths ("30 days hath September, ...") and leap years ("Years divisible by 4 are leap years; except those divisible by 100 aren’t; except those divisible by 400 are"). Remarkably, the First Sunday doomsday algorithm does the job with no multiplying, and no dividing anything by 4, or by 7.

Is it worth the trouble to learn the algorithm? After all, you don’t really need to find the days of historic dates. But how often do you wonder about the 15th of next month, or upcoming holidays, or the final exam schedule? Do you say “who knows, I don’t have a calendar in front of me”? Learning the algorithm will pay off for the rest of your life. And our calendar system is not going to be replaced by a more rational “star-date metric system” anytime soon.

Why didn’t the Romans come up with a formula for finding the day of the week? Because it’s difficult to calculate anything using Roman numerals! The Hindu-Arabic numeral system (with its handy zero) was introduced to Europe a thousand years after the Julian calendar. After another thousand years, Lewis Carroll approached the problem, followed by Dr. Conway 86 years later. Ideas spread more slowly before the internet.

[Tech note: The measure of difficulty for a method like this includes several factors: remembering intermediate variables; the number of operations, and the size of the numbers involved; and the problem of remembering the steps of the method itself, along with its numbers or “reminder phrases” for conversions. I believe this (averaged) count of arithmetic operations is the lowest achievable: 3 add, 1 subtract, 1 divide (even number by 2). Please email me if you find an improvement.]

Let’s get started with how the algorithm got its name.

What’s a First Sunday?

Here is typical calendar page, so we can talk about days of a particular month. Looking at this example, you can see the month’s first Sunday is the third. Let’s abbreviate this: MFS = 3.

Here’s the payoff for knowing the MFS: the day of the week is found by subtracting MFS from the date in question, and referring to the nearby table. This table simply associates numbers with the days of the week; a day’s number tells you “how many days past Sunday”.

Su Mo Tu We Th Fr Sa
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
N Day Memory Aid
0 Sunday None-day
1 Monday One-day
2 Tuesday Twos-day
3 Wednesday (3 is shaped like a W)
4 Thursday Fours-day
5 Friday Five-day
6 Saturday Six-urday

For example, the 7th of the example month can be figured as (7 - MFS) = (7 - 3) = 4 = Fours-day = Thursday. What if you were asked about the 2nd of this example month? You don’t want to subtract (2 - MFS) = (2 - 3) and get a negative number. Instead, add a seven into the calculation. In other words, ask yourself about the 9th instead of the 2nd. Answer: (9-3) = 6 = Six-urday = Saturday. (In the “Step 4” section below, another way of dealing with negative results is shown.)

Another type of question easily handled with this “first Sunday” approach is this: What date is payday, the last Friday of this month? Easy, if you remember the MFS = 3, meaning this month’s first Sunday is the 3rd. Add 5 (the number corresponding to Friday) and you know the 8th is a Friday, then add three sevens to get to payday, the 29th.

What we have just learned is the reason for the one and only subtraction operation, which appears in step 4 of the algorithm. The steps before that compute the MFS.

What’s a doomsday?

The word “doomsday” was chosen by Dr. J. H. Conway for a reference point in each year. The year’s doomsday is the day of the week for the last day in February. Dr. Conway looked for dates of each month that had the same day-of-the-week as the year's doomsday. He knew he was on to something when he saw that 4/4, 6/6, 8/8, 10/10, and 12/12 all met this criterion. In 2011, for example, the last day of February is a Monday. Therefore we can also say that 4/4/2011, 6/6/2011, etc. are all Mondays.

For our purposes, the month's doomsday is a number between zero and six, but an extra seven won't hurt: it's easier to remember 12/12 than December 5, the equivalent.
Here's the table of month’s doomsdays.

Month Month Number Month’s Doomsday Memory Aid
January 1 3 or 4 Use 3, three years out of four, but use 4 the fourth (leap) year
February 2 o or 1 Binary: leap year (1) or not (0)
March 3 0 The easiest month
April 4 = 4  
May 5 9 “9 to 5”
June 6 = 6  
July 7 11 “7-Eleven”
August 8 = 8  
September 9 5 “9 to 5”
October 10 = 10  
November 11 7 “7-Eleven”
December 12 = 12  
Just a few memory aids make this table easy:
  • Even months (except February) are trivial: use the month number.
  • Odd months (except January and March) are “swapped” according to the phrase “Work 9 to 5 at the 7-Eleven”, as shown in the table.
  • March is a zero. “Nothing” to remember! This happens because March's first Sunday is the year's first Sunday (definition below).
  • February is a binary “switch”, telling whether the year is a leap year. After all, February is the leap month.
  • January is a 3, three years out of four, but it’s a 4 the fourth year (the years divisible by 4).

Now back to the goal, which is to find the first Sunday of a month in question (the MFS). The "formula" is simple: it's the year's first Sunday (YFS) plus the month's doomsday.

MFS = YFS + MD

Definition: The year's first Sunday is the date of the first Sunday in March of the given year. It's a number between zero and six, which you'll use all year long. (When the first Sunday in March is the 7th, we say YFS=0.)

[Tech note: Just as Dr. Conway observed that 6/6 had the same day of the week as the last day in February, I note that the date of June’s first Sunday is 6 more that the date of March's first Sunday. The year’s first Sunday is the sevens complement of Conway's year’s doomsday: YFS = 7 – YD, where YD is the day of the week of the last day in February.]

Section Summary: We showed the relationship between the MFS (our goal) and the YFS, which is the date of the first Sunday in March of the given year. The formula is: MFS = YFS + month’s doomsday. Fortunately, in using the algorithm, you won’t have to think in terms of variables or formulas.

Step 1

As shown in the summary chart below, here is the procedure for step 1:

T = yy We will keep a running total “T” through the four steps. Initially, its value is yy, the two-digit year.
(if T is odd) T = T + 11 If the value is odd, add 11 to it. If even, do nothing.
T = T / 2 Divide T by 2. Easy, because T is even.
(if T is odd) T = T + 11 If the value is odd, add 11 to it. If even, do nothing.

That’s it for step 1! To remember this procedure, use the name given by the inventors, Fong and Walters: “Odd+11”. The amazing thing about this little procedure is that it accounts for leap years with no division by 4, and no “remainder” operations. Another amazing thing is the ease of remembering the three operations: “Odd+11, divide by 2, odd+11”.

[Tech note: The second addition of 11 could be “simplified” to an addition of 4 instead, since we immediately remove excess sevens. The simplicity of the repeated rule, however, outweighs the simplicity of the smaller number. Experts will also notice that you can remove excess sevens after the "divide by 2" operation.]

At the end of this step, you will have an even number in the range 0 – 66. You may (and generally you should) remove excess sevens at this point.

Step 2

The next step is to add the century's first Sunday (CFS) to the running total.

The CFS is the date of the first Sunday in March (i.e. the YFS) for a year ending with 00. Here is a table showing the CFS for various centuries. Surprisingly, we need only four columns, not seven, for all centuries in the Gregorian (modern) calendar.

0 2 4 5 <= The century’s first Sunday (CFS)
Remember: “No tuna for Friday”
n/a n/a 1500 1600  
1700 1800 1900 2000 This row covers American history
2100 2200 etc.    

The “nonsense phrase” to remind you of this table is "No tuna for Friday" (maybe you can come up with a better phrase). That gives you the table header, the CFS dates 0, 2, 4, 5. Recall that the relevant row of the table covers all of American history, the 1700s, 1800s, 1900s, and 2000s. For example, when solving for a date in the 1900s, you would count three pulses (or fingers): "1700, 1800 1900", associate that with "No tuna for", and you’ve got the CFS value, 4, to add to the running total. Future centuries are new rows in the table, as shown.

[Tech note: To compute the CFS for any Gregorian centurial number (cc, the first two digits of the year), there is a simple formula, thanks to Lawrence Baker:  CFS = ((cc mod 4) * 2 + 5) mod 7.  For everyday, or recent history date work, I’d rather remember the “nonsense phrase”, and not introduce this extra arithmetic.]

That’s it for step 2, unless you’re working on a date before Pope Gregory’s change to the calendar.

Julian Dates

Before the Gregorian correction, the leap-year rules were simpler, and, likewise, step 2 of the first Sunday doomsday algorithm is very simple for these early centuries.

What year is the dividing line between Julian and Gregorian dates? It depends on location. In Italy, it’s 1582, the year of the decree. In England and its colonies, it’s 1752. For a list telling when each region adopted the Gregorian calendar, see this historian's site. (The correction involves dropping days from the calendar. The web site just mentioned tells exactly which days were dropped in each region.) Assuming you know when the transition occurred, you can use the easy algorithm for Julian dates in the first part of the year, and use the regular algorithm for Gregorian dates after the correction. The only difference in the algorithm is the value of the CFS here in step 2.

The value to use for CFS for dates prior to the Gregorian correction couldn’t be simpler: it’s just cc, the centurial number! This is because the first Sunday in March for the year 100 is the 1st; for year 200, March 2nd, and so on for 15 centuries. There are examples of Julian date calculations in the Examples section below.

BC Dates

You can even calculate days for the years 45 BC through 1 BC with some extra effort, and perhaps a pencil. You just need to use (57 – |year|) in place of the BC year; for example, instead of 2 BC you use 55 AD . This trick handles the "negativeness" of BC years, and also the fact that the BC years 1, 5, 9, etc. are leap years. (The number 57 works well because the result of the subtraction is a small number in the first century, so step 2 consists of adding zero, the value of cc. For Americans, 57 is also an easy number to remember due to ketchup advertising.) Unfortunately, the leap day was not February 29 in those days, so more study is needed to pin down BC dates in February. Fine print: this works for the proleptic Julian calendar.

Now that we’ve added the CFS to the running total, the result after step 2 (after perhaps removing excess sevens) is the YFS for the given year ccyy. If you remind yourself throughout the year of this value, you can skip the first two steps for all your date questions in the current year! You simply begin at step 3 with the YFS you remember.

Step 3

The next step is to add the month’s doomsday (for mm) to the running total. This comes from the table shown above in the “What’s a doomsday?” section. Once again, the math is just adding a small number to the running total. The memory aids shown in that table are all you need to come up with the number.

The result of this step (after perhaps removing excess sevens) is the MFS for the given month. If you remind yourself throughout the month of this value, you can skip steps 1-3 for all your date questions in the current month! You simply begin at step 4 with the MFS you remember.

Tip: whenever you see a calendar, look at the number in the top of the Sunday column and say (for example) “this is a 3 month”. With this knowledge, you can enter the algorithm at step 4 with that “running total” (the MFS) for the given month.

Step 4

Subtract the running total (the MFS) from the date dd.  This is what we did in the introductory section, “What’s a First Sunday”. I suggested there that you might need to add 7 to the date in question, to avoid a negative result of the subtraction.

There is another way to deal with the problem of subtracting a number that is larger than the date dd. The solution is to “negate the negative”, taking advantage of the fact that, in modular arithmetic,

dd – T  =  7 – (T – dd).

For example, if you end up with (2-3), just go ahead and compute the negative answer (-1), than take the sevens complement, 7-1 = 6, or Saturday.

Summary Chart

If you’ve read all the sections above, you may never need to refer back to them, because the following chart summarizes the entire procedure, including the memory aids. You may wish to print the chart and refer to it as you follow the examples, and then practice on more dates of your choosing.

Of course, packing the whole method into one chart requires some abbreviation. The“math” column looks like a computer program, but the operations are very simple. Where brackets are used, like Table[x], it means x is converted to a new number by looking in a “table”. As you have seen, the “tables” are simple conversions you can remember thanks to some helpful phrases.

Summary of the First Sunday Doomsday Algorithm for the date mm/dd/ccyy


Step Math Description Conversion Tables and Memory Aids
1. T = yy
(if T is odd) T = T + 11
T = T / 2
(if T is odd) T = T + 11

If odd, add 11.
Then cut in half.
If odd, add 11.

Odd plus 11.”

Odd plus 11.” Again.
2. T = T + CFS_table[cc]

(Result is YFS)
Add the century’s first Sunday (CFS).
1700s 1800s 1900s 2000s Covers American history
0 2 4 5 (Remember “No tuna for Friday.”)
(For years prior to the Gregorian correction, use CFS = cc.)
3. T = T + MD_table[mm]





(Result is MFS)
Add the month’s doomsday.
Even month (except 2): Use the month number.
Odd month (except 1 or 3): Switch according to “Work 9 to 5 at 7-eleven.”
January: Use 3, three years out of four, but use 4 for leap years.
February: Use zero, but use 1 for leap years. It’s a binary switch.
March: Use zero. March is the easiest month.
4. Day = dd – T Subtract total from dd.
0=Sunday 1=Monday 2=Tuesday 3=Wed. 4=Thursday 5=Friday 6=Saturday
None-day One-day Twos-day 3 = “w” Fours-day Five-day Six-urday

 

Examples

The following examples show very concisely the four-step manipulation of the running total, leading to the resulting day of the week. One abbreviation needs explanation: a semicolon represents the subtraction of excess sevens.

What day was July 4, 1776 (U.S. independence day)?

1. 76 / 2 = 38
38; 3
yy is even, just cut in half.
T is even, nothing to add. Then subtract sevens (38-35=3).
2. + 0 = 3 First entry in the century table (first century in American history), so use the first word of “No tuna for Friday”. “No” stands for zero.
3. + 11 = 14; 0 The month (mm=7) gets switched to 11 according to the phrase “Work ... at 7-eleven”. Then remove a pair of sevens.
4. 4 - 0 = 4. Thursday dd=4. Result 4 = “Fours-day”.

Wow, we got lucky four times in that example. We avoided both “add 11” operations in step 1. Second, the CFS for the 1700s (step 3) was zero. And third, after removing excess sevens in step 4, the running total dropped to zero, making the final subtraction trivial.

The next example won’t have all those lucky breaks. What day was May 1, 1895?

1. 95 + 11 = 106
/ 2 = 53
+ 11 = 64; 1
yy is odd, so add 11.
Cut in half.
T is odd, so add 11. Remove excess sevens (64-63=1).
2. + 2 = 3 Recall the century table, “1700s, 1800s”. For cc=18, use the second word of “No tuna for Friday”. “Tuna” stands for 2.
3. + 9 = 12; 5 The month (mm=5) gets switched to 9 according to “Work 9 to 5...” . Then remove an excess seven.
4. 1 – 5 =  -4??
7 – (5-1) = 3. Wednesday
Darn, that’s going to be negative, so…
Go ahead and find the negative answer, then take the sevens complement. Result is 3, “Wednesday”.

 

August 4, 1962

1. 62 / 2 = 31
+ 11 = 42; 0
yy is even, just cut in half.
T is odd, so add 11. Remove excess sevens.
2. + 4 = 4 Add 4 for the 1900s. (“No tuna for Friday”.
3. + 8 = 12; 5 Even month; use the month number. Remove a seven.
4. 4  – 5 = –1??
7-1 = 6.  Saturday
Figure the negative result,
then complement to get 6, “Saturday”.

 

December 7, 1941 (Pearl Harbor day)

1. 41 + 11 = 52
/ 2 = 26
26
yy is odd, so add 11.
Cut in half.
T is even, nothing to add.
2. + 4 = 30; 2 Add 4 for the 1900s. Remove sevens.
3. + 12 = 14; 0 Even month; use the month number. Remove sevens.
4. 7 – 0 = 7; 0. Sunday None-day.

 

December 31, 1899

1. 99 + 11 = 110
/ 2 = 55
+ 11 = 66; 3
yy is odd, so add 11.
Cut in half.
T is odd, so add 11. Remove excess sevens.
2. + 2 = 5 Add 2 for the 1800s.
3. + 12 = 17; 3 Even month; use the month number. Remove sevens.
4. 31 – 3 = 28; 0. Sunday None-day.

 

January 1, 1900 (The next day, to test the previous example’s answer)

1. 0 / 2 = 0
0
Even, so just divide by 2.
T is even, nothing to add.
2. + 4 = 4 Add 4 for the 1900s.
3. + 3 = 7; 0 1900 was not a leap year, so this January's doomsday is 3, not 4!
4. 1 – 0 = 1. Monday One-day.

 

October 14, 1066 (The Battle of Hastings, Julian calendar)

1. 66 / 2 = 33
+ 11 = 44; 2
Even, so just divide by 2.
T is odd, so add 11. Remove excess sevens.
2. + 10 = 12 Simply add the centurial number cc for Julian years!
3. + 10 = 22; 1 Even month; use the month number. Remove sevens.
4. 14 – 1 = 13;6. Saturday Six-urday.

 

Another advantage of the first Sunday method is how it helps answer questions like the following:

What’s the date of Thanksgiving in 2013? Let’s run the algorithm through step 3. Since 13 is odd, we add 11 to get 24, Cut in half, getting 12 (even, nothing to add). Add the CFS (5 for the two-thousands), to get 17, remove sevens, result 3. The month’s doomsday for November is 7 (remember 7-Eleven), same as zero, so the total remains 3 as the month’s first Sunday. For the first Thursday (“Fours-day”), just add 4 to the MFS: 3 + 4 = 7. The Thursdays in November 2013 are on these dates: 7, 14, 21, and 28. Thanksgiving (fourth Thursday) is the 28th.

Easiest of all are Mother's Day (second Sunday in May) and Father's Day (third Sunday in June).

Final note

Do you know why there are seven days in a week? Thousands of years before the current era, the Egyptians had seven “sky gods”. Unlike modern gods, these can be seen by anyone; they are the sun, the moon, and the five “wandering stars”, i.e. the planets visible without a telescope. Sunday and Monday are obvious, and if you know a little French (or Spanish or Italian), you can spot the other planets thus: Tuesday (Mardi in French) is Mars, Wednesday (Mercredi) is Mercury, Thursday (Jeudi) is Jupiter, Friday (Vendredi) is Venus, and of course Saturday is Saturn, the highest of the gods. Next time you say “24/7”, thank the ancient Egyptians, who invented hours as well as weeks.

Why it works

Lewis Carroll, writing in Nature in 1887, presented a day-of the week method which set the standard for all methods to come. He required one to add together a “Century-Item,” a Year-Item, a Month-Item, and a Day-Item. The first Sunday method follows this same plan, but there is one disturbing difference: Where Carroll simply added the day-item (the day of the month dd) to the total, my fourth step requires a subtraction. How can this be better?

In the first Sunday method I have chosen the best available algorithms for the year-item, the century-item, and the month-item. In all three cases, it was best to produce a value which was not added to the day-item dd, but subtracted from it instead. Furthermore, adding the three “negative” items together happens to produce the month’s first Sunday (MFS), which has great practical value. The single subtraction that is required, in the fourth and final step, is justified by this practicality and by the simplicity of the other three steps. Following is the explanation for the “negative” nature of those three steps.

The year-item (our step 1) is “negative” because of the Fong-Walters “Odd+11” method, which is so well suited to mental calculation. Its result would have to be complemented to produce a value to add to a total with the day-item. The “Odd+11” method, applied to the year yy, happens to produce the date of the first Sunday in March, for that year in the first century.

Carroll’s original method for the year-item was “positive,’ and good enough for Conway to keep in his method. In brief, you add together the number of dozens in yy, the remainder of yy/12, and the number of fours in the remainder.

The century-item (our step 2) is “negative” because of the simplicity of using cc directly for Julian dates. This works because the first Sunday in March for the year 100 is the 1st; for the year 200, March 2nd, and so on for 15 centuries. For Gregorian dates, Lawrence Baker’s formula, 5+2(cc mod 4), is preferable to its complement, which Carroll used. (Carroll’s formula was 2(3-cc mod 4). The requirement for subtraction–actually a fours complement–makes it less desirable.)

The month-item (our step 3) is “negative” because Conway’s discovery, which uses the even month numbers directly and the “9 to 5 at 7-eleven” phrase, is so easy to remember. This “negativity” is what introduces a single subtraction in both Conway’s method and mine. Lewis Carroll’s original month-item, though it was indeed “positive,” was quite convoluted.

Others have presented methods with a “positive” month-item, but they require memorizing a table of values for the months. These include Justin White’s method at his calendarhome.com web site, and Arthur Benjamin and Michael Shermer’s similar method presented in their book, Secrets of Mental Math.[1]

There are other stars that aligned to make the first Sunday method work. Calling Sunday the zero day, Monday number one, etc., as Carroll did in 1887, yields good mnemonics like “Twos-day.” It also happens to match the international standard for dates, ISO8601, which counts Monday as number 1, and Sunday as 7. Finally, consider the first Sunday in March of the “year zero.” This is not a trick question – the year before AD 1 was the year we now call 1 BC. The first Sunday in March was on the 7th, making a perfect zero to which we can start adding our items.


[1] Benjamin, Arthur and Michael Shermer Secrets of mental math : the mathemagician’s guide to lightning calculation and amazing math tricks. New York: Three Rivers Press, 2006 p. 214 (Originally published in different form as Mathemagics by Lowell House, Los Angeles, in 1993.)