---
title: "Doomsday Algorithm"
summary: How to compute the day of the week of an arbitrary date in your head.
date: 2026-03-19
tags:
    - Math Trick
---

import DynamicDoomsdayDisplay from "@/components/blog/content/doomsday-algorithm/DynamicDoomsdayDisplay.astro";
import DynamicDoomsdayYearSelector from "@/components/blog/content/doomsday-algorithm/DynamicDoomsdayYearSelector.astro";

Generally, the idea is that there are certain dates in a year, that always fall on the same day of the week. We call those dates Doomsdays and there are rules for finding the Doomsday of every month. We get started with the easiest months:

## (Most) Even Months

We can use (almost) any even month for determining the Doomsday of a given year. For any even-numbered month except February, the same day is the Doomsday as the months number. This means:

- the 4th of April (4) is a Doomsday,
- the 6th of June (6) is a Doomsday,
- the 10th of October (10) is a Doomsday,
- the 12th of December (12) is a Doomsday.

Generally, for the Nth _even_ month, the Nth day is a Doomsday.

We can use this for our first weekday calculation. Let's ask ourselves, what weekday is Halloween (31st of October) this year?
We know that the 10th of October is a <DynamicDoomsdayDisplay display="weekday" /> because it is a Doomsday. Calculating 31 - 10 = 21, we know that it is exactly three weeks afterward a Doomsday.
Therefore, **Halloween is a Doomsday**. This year, Halloween falls on a <DynamicDoomsdayDisplay display="weekday" suffix="." />

To make finding the weekday easier, we can represent the weekdays as numbers ranging from 0 (Sunday) to 6 (Saturday). The number of the weekday of any given date can be computed by adding the number of the Doomsday weekday and the offset to the nearest Doomsday and then computing modulo 7 of that value.

Let's take a look at the remaining even month:

## February

The Doomsday is always the last day of february, e.g. **February 28 or 29**.

For <DynamicDoomsdayDisplay display="year" suffix="," /> February <DynamicDoomsdayDisplay display="february-day" /> is a <DynamicDoomsdayDisplay display="weekday" valueClass="font-bold" suffix="." />

Afterwards

<DynamicDoomsdayYearSelector />
