Zeller's congruence is an algorithm devised by Christian Zeller in the 19th century to calculate the day of the week for any Julian or Gregorian calendar date. It can be considered to be based on the conversion between Julian day and the calendar date.
Formula For the Gregorian calendar, Zeller's congruence is
h = ( q + ⌊ 13 ( m + 1 ) 5 ⌋ + K + ⌊ K 4 ⌋ + ⌊ J 4 ⌋ − 2 J ) mod 7 , {\displaystyle h=\left(q+\left\lfloor {\frac {13(m+1)}{5}}\right\rfloor +K+\left\lfloor {\frac {K}{4}}\right\rfloor +\left\lfloor {\frac {J}{4}}\right\rfloor -2J\right){\bmod {7}},}
for the Julian calendar it is
h = ( q + ⌊ 13 ( m + 1 ) 5 ⌋ + K + ⌊ K 4 ⌋ + 5 − J ) mod 7 , {\displaystyle h=\left(q+\left\lfloor {\frac {13(m+1)}{5}}\right\rfloor +K+\left\lfloor {\frac {K}{4}}\right\rfloor +5-J\right){\bmod {7}},}
where
h is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ..., 6 = Friday) q is the day of the month m is the month (3 = March, 4 = April, 5 = May, ..., 14 = February) K the year of the century ( ( a d j Y e a r ) mod 1 00 ) {\displaystyle ((adjYear){\bmod {1}}00)} . (The adjYear (adjusted year) is explained in the Note below.) J is the zero-based century (actually ⌊ ( a d j Y e a r ) / 100 ⌋ {\displaystyle \lfloor (adjYear)/100\rfloor } ) For example, the zero-based centuries for 1995 and 2000 are 19 and 20 respectively (not to be confused with the common ordinal century enumeration which indicates 20th for both cases).
⌊ . . . ⌋ {\displaystyle \lfloor ...\rfloor } is the floor function or integer part mod is the modulo operation or remainder after division 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:
a d j Y e a r {\displaystyle adjYear} = the actual year, for months from March to December.
a d j Y e a r {\displaystyle adjYear} = the previous year, for January and February. For an ISO week date Day-of-Week d (1 = Monday to 7 = Sunday), use
d = ( ( h + 5 ) mod 7 ) + 1 {\displaystyle d=((h+5){\bmod {7}})+1}
Analysis 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 {\displaystyle 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.
… excerpt ends here. Continue reading the full article.
