Menu Pane

In this page I will analyze the Zeller Congruence and will be more explicit than many other descriptions that usually assume some grounding in mathematics. In fact, I hope this explanation will also help a younger (middle school) audience .
The year is the period of revolution of the earth around the sun and is one of the three natural units for measurement of time. The other two are the day, defined by one rotation of the earth on its axis, and the month, marked by one revolution of the moon around the earth. No two of these units possess a common denominator, so that it is impossible to divide the year into an integral number of months or days without obtaining an unending decimal as a remainder. This is the cause of all the difficulties that the ancients encountered in their efforts to fit the linar month of 29 ½ days evenly into the year of about 365 ¼ days.
Twelve lunar months form a period of about 354 days , which is about 11 ¼ days short of the year. Attempts were made to keep the sun and and the moon in step with each other by putting 13 days in some months. The original Roman calendar was of this sort, but since there were no regular rules for the extra months the calendar became a source of political intrigue and was much abused. The Julian calendar made the sun the standard of measurement of the year, and the moon was disregarded entirely.
Up to well into the 16th century, the Julian calendar was in use, but because the Julian calendar ignored the extra ¼ day that is in a year, it became increasingly out of step with "real" time which could be measured using recurring and fairly accurate natural events such as the occurrence of the equinoxes (the times when the ecliptic, the plane of earth's orbit around the sun intersects the plane of the celestial equator). To correct for the discrepancy, Pope Gregory decided to make some adjustments to the calendar, based on a set of rules which went into effect on October 15, 1582:
The second rule is an adjustment of the first rule, and the third an adjustment of the second. Each adjustment upon adjustment was designed to make the calendar better synchronized with the passage of time. The outcome is that the Gregorian calendar overestimates the year by 26 seconds. It will be 3000 years before those seconds will have added up to an error of one day.
The history presented so far will help us understand a special mathematical formula known as Zeller's Congruence. It is a relatively simple but ingenious formula that calculates what day corresponds to a particular date. For instance, if one inputs November 28, 1953 into the formula, it produces "Saturday" as output, which is correct since that was my birthday.
There are some excellent discussions of Zeller's Congruence online:
But here I wish to address one aspect of the formula that is not explcitly discussed in most cases. This is the issue of an "anchor" or starting date, which will be discussed at the end after we have analyzed the Zeller Congruence.
Because it is a mathematical formula, Zeller's Congruence does not literally generate "Saturday", but the number 0 instead. The formula assigns numbers to days in the week, starting with 0 for Saturday and ending with 6 for Friday:
This is convenient and necessary since formulas work with numbers. Before going into detail, let me display the formula:
$$ day = (d + \left\lfloor{13(m + 1)/5}\right\rfloor + Y + \left\lfloor{Y/4}\right\rfloor - \left\lfloor{Y/100}\right\rfloor + \left\lfloor{Y/400}\right\rfloor) mod 7 $$The formula starts off with d, the day of the month. For example, 4 for May 4, 22 for September 22, ...
Example
9th August 1967: Y=1967, m=8, d=9
It does not look that bad, does it? It is essentially high school algebra except for perhaps the "mod 7" bit at the end. That simply means "divide by 7 and take the remainder". Mathematicians call this a "modulo 7" division - and the above just means "divide the overall sum by 7 and take the remainder". If you perform modulo 7 on the integers, you get the following:
As one can see, the cycle 0,1,2,3,4,5,6 repeats after 6 mod 7, which is the expected behavior. The sequence of 7 numbers repeats cyclically, just like the days of the week. Because the last operation executed in Zeller's formula is the remaindering after division by 7, the final result emerging from Zeller's Congruence has to be one of the numbers 0-6, and these numbers stand for the days of the week.
The other funny brackets are also a simple operation:
\( \left\lfloor{Y/4}\right\rfloor \) means take the floor of Y/4. In other words, After dividing by 4, convert the result to the integer that is less than or equal to the result:
$$ \begin{align} \left\lfloor{0/4}\right\rfloor &= \left\lfloor{0}\right\rfloor &= 0 \\ \left\lfloor{1/4}\right\rfloor &= \left\lfloor{0.25}\right\rfloor &= 0 \\ \left\lfloor{2/4}\right\rfloor &= \left\lfloor{0.5}\right\rfloor &= 0 \\ \left\lfloor{3/4}\right\rfloor &= \left\lfloor{0.75}\right\rfloor &= 0 \\ \left\lfloor{4/4}\right\rfloor &= \left\lfloor{1}\right\rfloor &= 1 \\ \left\lfloor{5/4}\right\rfloor &= \left\lfloor{1.25}\right\rfloor &= 1 \\ \left\lfloor{6/4}\right\rfloor &= \left\lfloor{1.5}\right\rfloor &= 1 \\ \left\lfloor{13/4}\right\rfloor &= \left\lfloor{3.25}\right\rfloor &= 3 \\ \left\lfloor{15/4}\right\rfloor &= \left\lfloor{3.75}\right\rfloor &= 3 \\ \left\lfloor{20/4}\right\rfloor &= \left\lfloor{5}\right\rfloor &= 5 \\ \left\lfloor{22/4}\right\rfloor &= \left\lfloor{5.5}\right\rfloor &= 5 \\ \left\lfloor{100/4}\right\rfloor &= \left\lfloor{25}\right\rfloor &= 25 \\ \end{align} $$(There is also a ceiling operator \( \left\lceil{X}\right\rceil \), which takes the next highest integer that is greater than or equal to X, but it is not used here).
The previous example worked out
9th August 1967: Y=1967, m=8, d=9
To summarize, Zeller's congruence takes a date from our specific Gregorian calendar, converts into a number of days (e.g. is it day 104?), finally divides that by 7, and takes the remainder. The remainder tells us what day of the week it is. The various parts of the formula take into account the adjustments made to the Gregorian calendar that were designed to keep it correctly synchronized with the passage of time.
For example, the most known adjustment is rule 1, the leap year adjustment. We normally assign 365 days to a year, but the year is in fact 365 ¼ days long when measured more accurately. Our calendar works by ignoring the extra quarter day for 3 years in a row, and in the 4th year after that, we add an extra day to the calendar to make up for the ignored quarter days. The year in which we add an extra day is called the leap year, because each day after February 29th (the extra added day) leaps over what it originally would have been. For instance, after February 29, what would have been Monday in a non-leap year becomes a Tuesday (leaps over to Tuesday), what would have been Tuesday becomes a Wednesday, and so on. Every 4 years the calendar is corrected and brought back in synch with the heavens. The \( \left\lfloor{Y/4}\right\rfloor \) part of the formula makes this adjustment: It takes the year number, divides it by 4, and takes the integer that is less than or equal to the result.
One needs to know that the formula considers January and February to be the 13th and 14th month of the previous year. In Zeller's congruence, the year starts on March 1. So the numbers to be used for m are:
Why this odd scheme? Well, it's because all months are 30 or 31 days long, except for February, which is the odd man out. By putting February at the end of the year, it turns out that all other months fall into a regular pattern (which we will show in the analysis of the second term, below) that make it possible to generate a simple expression for number of days in each month. The consequence of putting January and December at the end of the year, logically implies that they have to be placed at the end of the previous year. As a result, when one uses the formula to calculate a date that is in January or February, the year Y has to be decremented by 1 after the relocation of January and February to the previous year.
An online page that uses the Zeller congruence to convert dates to weekdays will of course allow users to enter the dates in the normal fashion. Internally, the months will be rearranged as discussed above.
Let us now analyze the formula.
We start with d as mentioned in the previous section. This is just the number day of the month. For example, d = 14 for the 14th of May.
Then, depending on which month the date refers to, we have to add all days from the previous months. A clever algebraic expression was used to do this. 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. We let the year start in March (and thus end in January and February), and arrange the number of days of this sequence of months in a row:
{31,30,31,30,31,31,30,31,30,31,31,28/29}
Since we will be performing mod 7 on these numbers in the end, we can do it now for convenience:
{3,2,3,2,3,3,2,3,2,3,3,0/1}
This makes it easier to see that there is a repeating pattern (3,2,3,2,3, repeat), which allows us to deduce that the cumulative count of these numbers is 13 every 5 months, so they can be approximated by a line of slope 13/5. The product of 13/5 times m gives the number of months up and including month m. To be more precise, we obtain this product by taking the ceiling of 13m/5 and multiplying by m. We get the same results if we use the floor of 13(m + 1)/5 (the reason for preferring the floor operation is that not all computer languages support the ceiling operation). By moving January and February to the end of the year, we have, as a lucky coincidence, uncovered a recurring pattern that is expressed in algebraically simple form.
We can work with the original number of days in each month and simply add them up by hand. Or we can use the expression \( 13(m + 1) /5 \). Either way, we get the same results for the weekday. For example, take a date such as 19 April in a non-leap year:
This is Y, the year (e.g. 1967). Note that each year has 365 days and 365 does not divide perfectly by 7 (stated otherwise, 365 mod 7 = 1). This means that the day of the week advances by one day each year. You can draw a simple timeline to help you visualize this:
If January 19th is Saturday this year, then next year it will be a Sunday, and the year after that a Monday (assuming it is not a leap year). So for every year that elapses, the day for a given date shifts a day further. And if it is a leap year, you add yet another day for a total shift of 2 days. After a number of years, you have accumulated 7 day shifts, so that January 19 is back to being Saturday in our example. So if 1967 years have elapsed, you have 1967 day shifts in total to consider.
(Some readers may point out that the year 1967 is not a total of 1967 years starting from 1582. But that does not matter because the calendar is cyclic and you can count the number of years from year 1 or the number of years from 1582. Either way, as you long as you count the correct number of years and take the rules into account, you will always get the right answer. Using the standard year is easier than counting from some specific date).
FOURTH TERM \( \left\lfloor{Y/4}\right\rfloor \)
For every multiple of four years, we add the extra leap year day, and therefore advance one day futher. \( \left\lfloor{Y/4}\right\rfloor \) is the total (integer) number of leap years and therefore the total number of days to advance.
Years divisible by 100 are not considered leap years, and must be ignored. The FOURTH term adds an extra leap year day for every multiple of 4 years, but this includes every multiple of 100 years since a multiple of 100 is also divisible by 4. So to ignore years divisible by 100, every multiple of 100 from the FOURTH TERM is subtracted away by the FIFTH TERM (which is why it is negative).
This implements the Pope Gregory's third rule. Years divisible by 400 are also divisible by 4 and 100, so the corresponding days were added by rule 1, removed by rule 2, and here they are added back again.
Newcomers to the Zeller congruence observe that the formula starts with d, the day in the month (e.g. 12 for the 12th of September, 25 for the 25th of May, etc.) and then is adjusted by the subsequent terms relating to the leap year or a century year and so on. Then they ask themselves, "all well and good that d is the 12th of September or whatever, but what day is that to start with? Is it a Friday, Wednesday, or a Monday - what is it?". Some websites mention that formulas similar to the Zeller congruence must use an anchor somewhere in the past - a known day corresponding to a date - and then add up the number of days after that by including leap years, subtracting century years, and so on in order to calculate the correct day number for the desired date. That makes sense, but one sees no explicit anchor in the Zeller congruence.
The brilliance of Zeller's congruence is that it embodies an implicit anchor simply in the definition of the days:
Any other of 6 different sequences could have been used (0 could have been Sunday, or Monday, or ...), but the one shown above requires the least computation. It is known that January 1, 1600, for instance, was a Saturday. Applying Zeller's congruence to that date yields the answer 0. Therefore, by assigning "Saturday" to the answer 0, all subsequent days come out correctly because the calendar repeats; the rules acting together cause it to repeat every 400 years.
And because the calendar repeats every 400 years, there is no need for a more brute force mathematical procedure that goes back to some reference date (with a known day of the week), and then adds the correct number of days all the way up to the desired date; that would have also worked, but would have been cumbersome.
Zeller's congruence is more efficient and compact: its rules implicitly specify in which 400 year cycle our desired date is in, and how far (how many days) we are into the cycle, so the day of the week can be quickly calculated.