1001Ferramentas
🗓️ Dates

Zeller Congruence — Day of Week

Compute the day of week for any date using Zeller Congruence — 1882 algorithm requiring only modular arithmetic. Shows each step (q, m, K, J, h) for didactic purposes. Supports Julian and Gregorian calendars.


    
About Zeller’s congruence

Published by Christian Zeller in 1882, the congruence works out the day of the week with modular arithmetic alone: h = (q + ⌊13(m+1)/5⌋ + K + ⌊K/4⌋ + ⌊J/4⌋ + 5J) mod 7 (Gregorian). January and February count as months 13 and 14 of the previous year. By convention: 0 = Saturday, 1 = Sunday, ..., 6 = Friday.

Zeller's congruence, step by step

Christian Zeller published a closed formula in the 1880s that returns the weekday of a date in a single expression, with no table and no loop. It still shows up in code because it is short and uses nothing but integer division — no floating point, no date library. The page breaks out each term, which helps both for checking an implementation and for seeing where every number comes from.

The trick that makes the formula work is treating January and February as months 13 and 14 of the previous year. That moves the variable-length month to the end of the year, so the leap day stops shifting every month after it. The same device appears in nearly every serious calendar algorithm, including the ones that convert to Julian day.

Note that the result starts on Saturday: the formula returns zero for Saturday, one for Sunday, and so on. It is a convention that catches out anyone expecting Sunday as zero, and the most common cause of a seven-day error in hastily copied implementations. The page also handles the Julian calendar, which changes two terms of the expression, and rejects dates that do not exist, such as 31 February.

Frequently asked questions

Why does the formula start on Saturday?
It falls out of how the terms were arranged to keep the expression simple, not from any meaning. Zeller started from a reference date that landed on a Saturday and did not normalise the result afterwards, because adding a constant would have lengthened the formula for no gain in accuracy.
What changes in the Julian calendar?
The Gregorian version carries the terms that correct for centuries, dividing the century by four. In the Julian calendar every multiple of four is a leap year with no century exception, so those terms give way to a constant and a multiple of the century. The page swaps the expression to match the calendar you pick.
Zeller or Doomsday, for programming?
Zeller, without question: it fits on one line and needs no table at all. Conway's method was designed for the human brain, which memorises well and divides badly. In code, integer division is cheap and memorisation does not exist, so the advantage reverses.

Related Tools