Calendar Wiki
Wikipedia This page uses content from the English Wikipedia. The original article was at Zeller's congruence. The list of authors can be seen in the page history. As with the Calendar Wikia, the text of Wikipedia is available under Creative Commons License. See Wikia:Licensing.

Zeller's congruence is an algorithm devised by Christian Zeller to calculate the day of the week for any calendar date.


For the Gregorian calendar the Zeller's congruence is

for the Julian calendar it is

where h is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ...), q is the day of the month, m is the month, J is the century (actually ⌊year / 100⌋) and K the year of the century (year mod 100). January and February are counted as month 13 and 14 of the previous year.

In a computer implementation where a modulo result for a negative number is negative, the simplest way to get a result in the range 0 - 6 is replacing - 2 J by + 5 J and - J by + 6 J.


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:

  • represents the progression of the day of the week based on the day of the month, since each successive day results in an additional offset of 1 in the day of the week.
  • represents the progression of the day of the week based on the year. Assuming that each year is 365 days long, the same date on each succeeding year will be offset by a value of .
  • Since there are 366 days in each leap year, this needs to be accounted for by adding an additional day to the day of the week offset value. This is accomplished by adding to the offset. This term is calculated as an integer result. Any remainder is discarded.
  • Using similar logic, the progression of the day of the week for each century may be calculated by observing that there are 36524 days in a normal century and 36525 days in each century divisible by 400. Since and , the term : accounts for this (again using integer division and discarding any fractional remainder). To avoid negative numbers, this term can be replaced with with equivalent results.
  • The term can be explained as follows. Zeller observed that, by starting each year on March 1, the day of the week for each succeeding month progressed by multiplying the month by a constant value and discarding the fractional remainder.
  • The overall function, , normalizes the result to reside in the range of 0 to 6, which yields the index of the correct day of the week for the date being analyzed.

The reason that the formula differs for the Julian calendar is that this calendar does not have a separate rule for leap centuries and is offset from the Gregorian calendar by a fixed number of days. Both of these differences can be accounted for by replacing the term with the term , or to avoid negative numbers.

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.


Algorithm Z(y, m, d)
Input: The year y, month m (1 ≤ m ≤ 12), and day d (1 ≤ d ≤ 31).
Output: The day of the week.
t ← (0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4)
n ← (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)
if m < 3
yy - 1
w ← (y + ⌊y/4⌋ - ⌊y/100⌋ + ⌊y/400⌋ + tm-1 + d) mod 7
return nw

See also[]


External links[]