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.
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 2010 (02/02/2010 in DD/MM/YYYY), the algorithm counts the date as the second day of the fourteenth month of 2009 (02/14/2009 in DD/MM/YYYY format)
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 proleptically, 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 − 2J with + 5J and − J with + 6J.
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 in representing the year. But when using a computer, it is simpler to handle the modified year Y and month m, which are Y - 1 and m + 12 during January and February:
For the Gregorian calendar, Zeller's congruence becomes
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 RFC 3339, 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 m∈ [3, 14] ∩ Z 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 m, resulting in a starting value of 0 for Sunday.
In number theory, the law of quadratic reciprocity is a theorem about modular arithmetic that gives conditions for the solvability of quadratic equations modulo prime numbers. Due to its subtlety, it has many formulations, but the most standard statement is:
A triangular wave or triangle wave is a non-sinusoidal waveform named for its triangular shape. It is a periodic, piecewise linear, continuous real function.
In mathematics, the floor function is the function that takes as input a real number x, and gives as output the greatest integer less than or equal to x, denoted ⌊x⌋ or floor(x). Similarly, the ceiling function maps x to the least integer greater than or equal to x, denoted ⌈x⌉ or ceil(x).
In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operations and directly supported by the processor. Most bitwise operations are presented as two-operand instructions where the result replaces one of the input operands.
Dominical letters or Sunday letters are a method used to determine the day of the week for particular dates. When using this method, each year is assigned a letter depending on which day of the week the year starts. The Dominical letter for the current year 2024 is GF.
In mathematics a polydivisible number is a number in a given number base with digits abcde... that has the following properties:
The determination of the day of the week for any date may be performed with a variety of algorithms. In addition, perpetual calendars require no calculation by the user, and are essentially lookup tables. A typical application is to calculate the day of the week on which someone was born or a specific event occurred.
In number theory, a formula for primes is a formula generating the prime numbers, exactly and without exception. Formulas for calculating primes do exist; however, they are computationally very slow. A number of constraints are known, showing what such a "formula" can and cannot be.
The Doomsday rule, Doomsday algorithm or Doomsday method is an algorithm of determination of the day of the week for a given date. It provides a perpetual calendar because the Gregorian calendar moves in cycles of 400 years. The algorithm for mental calculation was devised by John Conway in 1973, drawing inspiration from Lewis Carroll's perpetual calendar algorithm. It takes advantage of each year having a certain day of the week upon which certain easy-to-remember dates, called the doomsdays, fall; for example, the last day of February, April 4 (4/4), June 6 (6/6), August 8 (8/8), October 10 (10/10), and December 12 (12/12) all occur on the same day of the week in any year.
In computing, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another, called the modulus of the operation.
In computer science and mathematics, the Josephus problem is a theoretical problem related to a certain counting-out game. Such games are used to pick out a person from a group, e.g. eeny, meeny, miny, moe.
In number theory, the law of quadratic reciprocity, like the Pythagorean theorem, has lent itself to an unusually large number of proofs. Several hundred proofs of the law of quadratic reciprocity have been published.
The ISO week date system is effectively a leap week calendar system that is part of the ISO 8601 date and time standard issued by the International Organization for Standardization (ISO) since 1988 and, before that, it was defined in ISO (R) 2015 since 1971. It is used (mainly) in government and business for fiscal years, as well as in timekeeping. This was previously known as "Industrial date coding". The system specifies a week year atop the Gregorian calendar by defining a notation for ordinal weeks of the year.
An ordinal date is a calendar date typically consisting of a year and an ordinal number, ranging between 1 and 366, representing the multiples of a day, called day of the year or ordinal day number. The two parts of the date can be formatted as "YYYY-DDD" to comply with the ISO 8601 ordinal date format. The year may sometimes be omitted, if it is implied by the context; the day may be generalized from integers to include a decimal part representing a fraction of a day.
Cubic reciprocity is a collection of theorems in elementary and algebraic number theory that state conditions under which the congruence x3 ≡ p (mod q) is solvable; the word "reciprocity" comes from the form of the main theorem, which states that if p and q are primary numbers in the ring of Eisenstein integers, both coprime to 3, the congruence x3 ≡ p is solvable if and only if x3 ≡ q is solvable.
In mathematics, a Beatty sequence is the sequence of integers found by taking the floor of the positive multiples of a positive irrational number. Beatty sequences are named after Samuel Beatty, who wrote about them in 1926.
A calendrical calculation is a calculation concerning calendar dates. Calendrical calculations can be considered an area of applied mathematics. Some examples of calendrical calculations:
In computer science, multiply-with-carry (MWC) is a method invented by George Marsaglia for generating sequences of random integers based on an initial set from two to many thousands of randomly chosen seed values. The main advantages of the MWC method are that it invokes simple computer integer arithmetic and leads to very fast generation of sequences of random numbers with immense periods, ranging from around to .
In number theory, the Fermat quotient of an integer a with respect to an odd prime p is defined as
In modular arithmetic, Barrett reduction is a reduction algorithm introduced in 1986 by P.D. Barrett.
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.