Calculate the date of any day!
This is a method called the Doomsday algorithm which is used to calculate the date of any day,month, and year (greater than 0) in the Gregorian calendar. This method can be done in your head quite quickly or using a computer program (of course). Scroll down half way if you wish to immediately jump to the steps of the algorithm.
Things to memorize for the algorithm:
Values of dates
Sunday = 0, Monday = 1, Tuesday = 2,
Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6
*Notice how the value of Sunday isn’t 7 it is instead 0.
Anchor day of the century
year_mod = year % 400
if (year_mod >= 0 & year_mod < 100) then anchorday = 2 (Tuesday);
else if (year_mod >= 100 & year_mod < 200) then anchorday = 0 (Sunday);
else if (year_mod >= 200 & year_mod < 300 ) then anchorday = 5 (Friday);
else if (year_mod >= 300 & year_mod < 400 ) then anchorday = 3 (Wednesday);
Shortcut for recent centuries:
1800 - 1899: 5 (Friday)
1900 - 1999: 3 (Wednesday)
2000 - 2099: 2 (Tuesday)
2100 - 2199: 0 (Sunday)
Doomsday of the month
Leap year = 4
Non-leap year = 3
Leap year = 29
Non-leap year = 28
*For more doomsday’s of the month, Wikipedia has an article - entitled Doomsday Rule - on this algorithm that includes multiple doomsday of the month.
( (last two digits of year)
14*( (last two digits of year) % 12)
3*( ( (last two digits of year) % 12) % 4)
Take the last two digits of the year, plus 14 times the last two digits of the year modulos 12, minus 3 times the last two digits of the year modulos 12 and then again modulos 4, all divided by 12. Then add the century anchor day and modulos this new sum by 7.
1. Determine the anchor day of the century
2. Calculate the doomsday. This will result in a number between 0 and 6. Corresponding to Sunday through Saturday. Shown above under “Values of dates”.
Ex. if the doomsday is 0, then it is a Sunday. If it is a 3, then it is a Wednesday.
3. Find the doomsday of the month. The date of this day will be whatever date you found in step two.
4. Calculate the value of the absolute difference between the doomsday of the month and your day, modulos 7. You modulos 7 so you don’t end up counting over several weeks. For example if the absolute value of the doomsday minus your day was 15. This can be expressed as two weeks and one day away. If a number is one week or seven day away it will land us on the same day. This is why we are interested in the modulo of the absolute difference. In equation form this looks like abs(doomsday_of_month - your_day) % 7 = |doomsday_of_month - your_day| % 7
5. If the doomsday of the month is greater than your day, count back the number found in step 4 from the doomsday found in step 2.
If the doomsday of the month is less than your day, count up the number of days found in step 4 from the doomsday found in step 2.
1. The anchor day is 3 (we know from the shortcut for recent centuries)
1949 % 400 = 349
349 >= 300
349 < 400
Therefore the anchor day of the century is 3, which is Wednesday.
2. Calculate the doomsday
( (last two digits of year) = 49
14*( (last two digits of year) % 12) = 14*(49%12) = 14*1 = 14
3*( ( (last two digits of year) % 12) % 4) = 3*((49%12)%4) = 3(1%4) = 3*1 = 3
+ century anchor day = 3
In a less spaced out form:
doomsday = ((((1/12)*((year % 100) + 14*((year % 100) % 12) - 3*(((_year%100)%12)%4))) + cent_anch_day)%7);
(((49 + 14 - 3) / 12) + 3) % 7 = (((63 - 3) / 12) + 3 % 7) = ((60/12) + 3) % 7 = (5+3) % 7 = 1
* Make sure you are adding the century anchor date.
The doomsday is 1, which is Monday
3. Doomsday of the month
The example month is April. In April the doomsday is 4. Conveniently is the forth day of the forth month (04/04). This pattern also occurs for June (06/06), August(08/08), October (10/10), and December (12/12).
The example day is the 23rd. The doomsday of the month is the 4th. The absolute difference between the example day and the doomsday of the month modulos 7 is:
abs(23-4) % 7 = |23-4| % 7 = |19| % 7 = 19 % 7 = 5
5. Since the doomsday of the month comes before the example day, we will count up from the doomsday of the month by the value we found in step 4.
April 4th is a Monday(1). Counting up five days.
5. Saturday !!
Therefore Saturday is the date of the day, month, and year that was chosen for the example.
The percentage sign symbol in this tutorial denotes the modulo function. Therefore 4 % 7, would be 4 modulo 7 and the result would be 4.
For those unfamiliar with the modulo function it can also be described as the remainder from dividing the numerator by the largest multiple of the denominator that is not larger than the numerator.
Ex: 15 % 6 = 15 modulo 6
6 can go into 15 twice without being larger than 15 itself. Thus the remainder of 15 divided by 6*2 is 3.
x % y = Remainder of x / z = x - z
where z = c*y is the greatest number which satisfies the conditions:
x >= z
c is any natural number
The function abs(x) also denoted as |x| returns the absolute value of whatever is between the brackets - in this case it is x. The absolute value is the positive value of whatever is passed to it. So if you pass a negative number to the absolute function it will come out positive. If you pass a positive number to the absolute function it will come out positive.
abs(-7) = |-7| = 7,
abs(86) = |86| = 86,
abs(-1100) = |-1100| = 1100
When you see anything calling for the last two digits of the year, a arithmetic method of getting this is (year % 100). This works well for computers. However, for humans its a simple matter of disregarding all but the last two digits of the year in our minds.
I came up with this after writting a program in C++ for a programming class to calculate the date of any day,month, and year. Our class used the website http://www.timeanddate.com/date/doomsday-weekday.html as a reference to build our programs. It provides instructions on how to calculate the doomsday and find the date of any day,month, and year. I distilled the algorithm for the doomsday into its arithmetic form from the code I had written on the computer and then used Wolfram Alpha to help simplify the formula for human use.
For more doomsday’s of the month and a more indepth look at this algorithm you can visit the Wikipedia page of the Doomsday Rule: