FANDOM


Wikipedia-logo-en 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.

FormulaEdit

For the Gregorian calendar the Zeller's congruence is

h = \left(q + \left\lfloor\frac{(m+1)26}{10}\right\rfloor + K + \left\lfloor\frac{K}{4}\right\rfloor + \left\lfloor\frac{J}{4}\right\rfloor - 2J\right) \mod 7,

for the Julian calendar it is

h = \left(q + \left\lfloor\frac{(m+1) 26}{10}\right\rfloor + K + \left\lfloor\frac{K}{4}\right\rfloor + 5 - J\right) \mod 7,

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.

AnalysisEdit

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:

  • q 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.
  • K 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 365\mod 7 = 1.
  • 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 \left\lfloor\frac{K}{4}\right\rfloor 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 36525\mod 7 = 6 and 36524\mod 7 = 5, the term :\left\lfloor\frac{J}{4}\right\rfloor - 2J accounts for this (again using integer division and discarding any fractional remainder). To avoid negative numbers, this term can be replaced with 5J + \left\lfloor\frac{J}{4}\right\rfloor with equivalent results.
  • The term \left\lfloor\frac{(m+1)26}{10}\right\rfloor 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, \mod 7, 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 \left\lfloor\frac{J}{4}\right\rfloor - 2J with the term 5 - J, or 5 + 6J 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.

AlgorithmEdit

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 alsoEdit

ReferencesEdit

External linksEdit

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.