The doomsday algorithm is a mental algorithm for finding the day of the week of a given date by first finding the weekday of the last day of February, called that year's doomsday (Conway 1973, pp. 28-29; Numberphile 2021). It is a specialized method of calendar arithmetic for weekday calculations. The following form uses the Gregorian calendar for every positive-numbered year. Encode Sunday through Saturday by 0 through 6.
Write the positive integer year as , where
and
are nonnegative integers
and
.
The century anchor
takes the values 2, 0, 5, 3 when the remainder of
upon integer
division by 4 is 0, 1, 2, 3, respectively. Set
and
, where
is the floor function.
The doomsday weekday is
where mod selects the remainder from 0 through 6 (Conway 1973, p. 29).
A Gregorian year is a leap year iff its number is a multiple of 4 and is either not a multiple of 100 or is a multiple of 400. February then has 29 days instead of 28 (Dershowitz and Reingold 1990, p. 903).
Dates on doomsday include January 3 (January 4 in a leap year), the last day of February, March 7, April 4, May 9, June 6, July 11, August 8, September 5, October 10, November 7, and December 12. Count forward or backward from one of these dates, using modular arithmetic with modulus 7, to obtain the weekday of the desired date (Conway 1973, p. 29).