Zeller's congruence is a modular arithmetic algorithm devised by Christian Zeller in the 19th century for calculating the day of the week for a given date in either the Gregorian or Julian calendar. It expresses the weekday as a congruence modulo 7, combining contributions from the day of the month, the month, the year within the century, and the century itself.
In Zeller's method, months are numbered from March (= 3) through February (= 14), with January and February treated as the 13th and 14th months of the previous year; this "adjusted year" convention simplifies handling of February and leap years. The result is typically returned as an index (commonly 0âÂÂ6) that can be mapped to weekday names, with alternative mappings (such as ISO weekday numbering) obtainable by a simple conversion.
Several equivalent forms and implementations are in common use, including versions that combine century and year terms into a single four-digit year and versions that avoid negative intermediate values. Because calendar adoption differed by region and dates may be interpreted proleptically, the applicable calendar (Julian or Gregorian) can affect the computed weekday for historical dates.
For the Gregorian calendar, Zeller's congruence is
for the Julian calendar it is
where
Note: In this algorithm January and February are counted as months 13 and 14 of the previous year. E.g. if it is 2 February 2026 (02/02/2026 in DD/MM/YYYY), the algorithm counts the date as the second day of the fourteenth month of 2025 (02/14/2025 in DD/MM/YYYY format) So the adjusted year above is:
For an ISO week date Day-of-Week d (1 = Monday to 7 = Sunday), use
These formulas are based on the observation that the day of the week progresses in a predictable manner based upon each subpart of that date. Each term within the formula is used to calculate the offset needed to obtain the correct day of the week.
For the Gregorian calendar, the various parts of this formula can therefore be understood as follows:
The reason that the formula differs between calendars is that the Julian calendar does not have a separate rule for leap centuries and is offset from the Gregorian calendar by a fixed number of days each century.
Since the Gregorian calendar was adopted at different times in different regions of the world, the location of an event is significant in determining the correct day of the week for a date that occurred during this transition period. This is only required through 1929, as this was the last year that the Julian calendar was still in use by any country on earth, and thus is not required for 1930 or later.
The formulae can be used , but "Year 0" is in fact year 1 BC (see astronomical year numbering). The Julian calendar is in fact proleptic right up to 1 March AD 4 owing to mismanagement in Rome (but not Egypt) in the period since the calendar was put into effect on 1 January 45 BC (which was not a leap year). In addition, the modulo operator might truncate integers to the wrong direction (ceiling instead of floor). To accommodate this, one can add a sufficient multiple of 400 Gregorian or 700 Julian years.
For 1 January 2000, the date would be treated as the 13th month of 1999, so the values would be:
So the formula evaluates as .
(The 36 comes from , truncated to an integer.)
However, for 1 March 2000, the date is treated as the 3rd month of 2000, so the values become
so the formula evaluates as .
The formulas rely on the mathematician's definition of modulo division, which means that âÂÂ2 mod 7 is equal to positive 5. Unfortunately, in the truncating way most computer languages implement the remainder function, âÂÂ2 mod 7 returns a result of −2. So, to implement Zeller's congruence on a computer, the formulas should be altered slightly to ensure a positive numerator. The simplest way to do this is to replace with and with .
For the Gregorian calendar, Zeller's congruence becomes
For the Julian calendar, Zeller's congruence becomes
One can readily see that, in a given year, the last day of February and March 1 are a good test dates.
As an aside note, if we have a three-digit number abc, where a, b, and c are the digits, each nonpositive if abc is nonpositive; we have (abc) mod 7 = 9*a + 3*b + c. Repeat the formula down to a single digit. If the result is 7, 8, or 9, then subtract 7. If, instead, the result is negative, then add 7. If the result is still negative, then add 7 one more time. Utilizing this approach, we can avoid the worries of language specific differences in mod 7 evaluations. This also may enhance a mental math technique.
Zeller used decimal arithmetic, and found it convenient to use J and K values as two-digit numbers representing the year and century. But when using a computer, it is simpler to handle the year as a single 4-digit number. For the Gregorian calendar, Zeller's congruence becomes
where is , defined in the section above.
In this case there is no possibility of underflow due to the single negative term because .
For the Julian calendar, Zeller's congruence becomes
The algorithm above is mentioned for the Gregorian case in , Appendix B, albeit in an abridged form that returns 0 for Sunday.
At least three other algorithms share the overall structure of Zeller's congruence in its "common simplification" type, also using an and the "modified year" construct.
Both expressions can be shown to progress in a way that is off by one compared to the original month-length component over the required range of , resulting in a starting value of 0 for Sunday.
Each of these four similar imaged papers deals firstly with the day of the week and secondly with the date of Easter Sunday, for the Julian and Gregorian calendars. The pages link to translations into English.