Skip to main content

The doomsday algorithm

Now that I have gone through all the things to remember when calculating the weekday of any given date it's finally time to go through the actual algorithm. The basic odea is to figure out the weekday of the doomsday and then use those dates to calculate the weekday of the actual date relative to them.

First you need to figure out the anchor date for the century. Remember the series 5, 3, 2, 0 which correspond to the respective centuries 1800, 1900, 2000 and 2100 (or any multiples of 400 from them). I'll use today's date (21.1.2024) as an example, so the anchor date for 2000 is 2.

Next you need to do some actual math. First drop the first two numbers of the year and figure out how many full 12's there are. E.g. 2024 becomes 24 and that's 2 twelves. Add that to the anchor date and you get 4.

Then, if the year wouldn't have been a multiple of 12 check the multiples of four in that remaining amount. For example last year (23) only fits 12 once and the remainder is 11, so that makes 2 times four. Add that to the number again.

Finally divide the remaining number by 7 and check the extra again. With todays date the sum is 4 which doesn't contain any multiples of seven the final number is four. This is the weekday of the doomsday of the year and the fourth day of the week is Thursday.

Now you just need to recall the doomsday for January. Remember that the first two doomsdays of the year depends whether it's a leap year or not. 2024 happens to be a leap year so the doomsday for January is 4 (instead of 3 for a regular year). So now we know that 4th of January was Thursday. 21st is 17 days after that so you can substract multiples of 7 from it to make the counting a bit easier. Subtracting 14 from 17 leaves 3 which means today is 3 days ahead from Thursday so today must be Sunday!