The Mathematics: Zeller's Congruence & Doomsday Rule
How It WorksCalculating the day of the week for any Gregorian calendar date uses Zeller's Congruence, an algorithm devised by German mathematician Christian Zeller in 1882:
h = (q + floor(13(m+1)/5) + K + floor(K/4) + floor(J/4) - 2J) mod 7
Where q is the day of the month, m is the shifted month (March=3, January=13, February=14 of the prior year), K is the year of the century, and J is the zero-based century.
Renowned mathematician John Conway also invented the Doomsday Rule, utilizing anchor dates (e.g. 4/4, 6/6, 8/8, 10/10, 12/12) that share the same weekday every year.