Jump to content
xisto Community

Doomsday Algorithm finding the day of the week for a date

Recommended Posts

Doomsday algorithm
The Doomsday algorithm is a way of calculating the day of the week of a given date. It is perpetually accurate since the Gregorian calendar moves in cycles of 400 years. It makes use of the fact that, in each year, certain dates are all on the same day of the week.

The algorithm was invented by John Horton Conway. It can be used for either the Gregorian Calendar or the Julian Calendar, but note that Julian calendar Doomsdays usually occur on different days from the Gregorian calendar Doomsdays.

The algorithm
The algorithm has three steps, namely, finding the anchor day for the century, finding a year's doomsday, and finding the day of week of the day in question.

To find a century's anchor day, begin by finding the century which the date falls in. (For the purposes of this calculation, century years will be treated as though they fall in the century that follows, even though they technically fall in the same century as the years before them. 2000 is therefore part of the twenty-first century, not the twentieth century.) A year's century number is equal to its first two digits plus one (so 1966 is in the twentieth century). Take the century number and multiply by 5. Separately, take the integral part of the quotient when the century number minus one is divided by four. Add these two numbers (the product of the multiplication and the integral of the division). Taking the remainder mod 7 is often done at this point to make the numbers more manageable, since it won't affect the result. Now count forward that number of days from Thursday to get the anchor day for the century. For example, the calculation for the twentieth century is: multiply the century number 20 by 5 to get 100; subtract 1 from the century number and then divide by 4 to get 4; sum 100 and 4 to get 104; find the remainder mod 7 to get 6; count 6 days on from Thursday for the answer, Wednesday. Similarly, the anchor date for the twenty-first century is Tuesday.

Next, one must find the year's Doomsday. To accomplish that according to Conway, begin by taking the integral part of the quotient when the year's last two digits are divided by 12. Next, determine the remainder of this first quotient. After that, take the integral part of this number when it is divided by 4. Finally, determine the sum of the three numbers. (This is equivalent mod 7, as it must be, to the sum of the last two digits plus those digits divided by four.)

Now count forward the specified number of days from the anchor day (again taking remainder mod 7 can be done) to get the year's Doomsday.

The following days all occur on Doomsday for any given Gregorian year:

January 31 (or "January 32", ie February 1, in leap years)
February 28 (or February 29 if it's a leap year)
"March 0" (a backwards extension of the calendar, equivalent to the last day of February.)
April 4
May 9
June 6
July 11
August 8
September 5
October 10
November 7
December 12
The dates listed above were chosen to be easy to remember; the ones for even months are simply doubles, 4/4, 6/6, 8/8, 10/10, and 12/12. Four of the odd month dates (5/9, 9/5, 7/11, and 11/7) are based on the phrase "I work from 9 to 5 at the 7-11."

The following is the algorithm in C. Please note that division in C (using the / operator) is integer division and that the % operator is the modulo operator.

Set "year" to whatever year (this case is 2005) computation is desired and the numeric values of the days of the week are:

0 â Sunday
1 â Monday
2 â Tuesday
3 â Wednesday
4 â Thursday
5 â Friday
6 â Saturday
// Determine the anchor day for the century
year = 2005;
century = year/100 + 1;

a = century * 5;
b = (century - 1) / 4;
c = a + b;
anchor = (c + 4) % 7;

// Determine the Doomsday for the year in question
e = (year % 100)/12;
f = (year % 100)%12;
g = f/4;
h = e + f + g;
dday = (h + anchor) % 7;
"anchor" is the anchor day for the century and "dday" is the doomsday for the year. If "dday" is found to be Monday, then January 3 (or 4th), February 28 (or 29th), March 0, April 4, May 9, etc. (see above). To find the day of the date in
question, determine the number of days away from the doomsday for that month and add it to "dday" modulo 7.

This article has been taken from the wikipedia and is free under the gnu documentation license. If the forum doesn't allow such "knowledge sharing" kindly let me know.

have fun calculating the day of the week for any date.

I will in near future put up a complete working code in java to do the same.

more useful information is also available at

Share this post

Link to post
Share on other sites

nice.... been a very long time since I saw this. I used to have a calendar on an A4 sheet which would tell you the day of the week for any date within a span of 10,000 years. That was nearly 10 years ago. I still might have it at home. The first time I read about this was in a book by Shakuntala Devi, a very renowned number theorist. 'Figuring' was the name if I'm not mistaken. She could actually do the whole thing in her head and give you the day of the week in seconds!!! She actually visited my mom's school when my mom was a student (35 years ago!) and gave a demonstration. heh :D... anyway great find.

Share this post

Link to post
Share on other sites

Ah, interesting. I think I've heard of it before but never really looked through it. Nice. Although it's mere weeks until I return to university so my brain currently doesn't like anything math related, otherwise an awesome post :D haha

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.