Zeller’s Rule: What Day of the Week Is It?

We’ve been celebrating a new year with some examination of dates: the fact that 2020 is a new decade (sort of) and a leap year (definitely), and now, some details about how the whole Gregorian calendar works. Some of this is collected in the Ask Dr. Math FAQ on The Calendar and the Days of the Week.

The formula

Our first question is from 1997:

Formula for the Day of the Week

Would you please tell us what day of the week the Declaration of Independence was signed on as well the formula to determine such? Thank you very much!

Doctor Rob answered, with what I presume is the source of the FAQ’s version; but first, a historical note:

This is a trick question, of course.  The date at the top of the document is July 4th, 1776.  I believe it was actually signed on July 2nd, however.

Ignoring this historical technicality, the day of the week upon which July 4th, 1776, fell was Thursday.

So how can we determine this mathematically?

The rule is quite complicated.  It goes like this:

Let k be the day of the month.  In this case, k = 4.

Let m be the month, counting March as 1 and February as 12.  (Here January and February are considered as the last months of the preceding year.  This is to make Feb. 29th [if any] be the last day of the year.  This also means that the values of C and D are those for the preceding year, so, for example, 1 Jan 2000 would have C = 19 and D = 99.)  In this case, m = 5 (July).

Let D be the last two digits of the year.  In this case, D = 76.

Let C be the first two digits of the year (the century).  In this case, C = 17.

For any real number x, let [x] be the greatest integer less than or equal to x, which you get by truncating any fractional part.  Then compute:

f = k + [(13*m-1)/5] + D + [D/4] + [C/4] - 2*C.

Once you have this, then  f - 7*[f/7] will give you the day of the week, with Sunday = 0, Monday = 1, and so on.

As we’ll see below, he has slightly misstated what [x] means; if x is negative, you can’t just truncate. Technically, [x] is the “floor function”, also written as floor(x) or \(\lfloor x \rfloor\).

The last step means finding the (positive) remainder after division by 7. This, too, will need further discussion.

In your case
f = 4 + [64/5] + 76 + [76/4] + [17/4] - 34
  = 4 + 12 + 76 + 19 + 4 - 34
  = 81
and f - 7*[f/7] = 81 - 7*[81/7] = 81 - 7*11 = 81 - 77 = 4, or Thursday.

That last step means that when we divide 81 by 7, we get 11 R 4; that is, \(81 = 11\times7+4\).

This rule was given by a certain Rev. Zeller, and so is called Zeller's Rule.  This works for the Gregorian calendar only.  There is a simpler version for the Julian calendar.  Recall that English-speaking countries used the Gregorian calendar beginning 14 Sep 1752, and before that used the Julian calendar.

The rule is also called Zeller’s Congruence, a reference to its use of modular arithmetic (the remainder).

Just the FAQ, please

This formula is given a little more fully in the FAQ (which uses a better example, and was edited a couple times over the years as we found that the original version was misstated, misinterpreted, or misapplied by readers). Here it is, with an extra small correction that was discussed but never made:

Zeller’s Rule

The following formula is named Zeller’s Rule after a Reverend Zeller. [x] means the greatest integer that is smaller than or equal to x. For positive numbers, you can find this number by just dropping everything after the decimal point. For example, [3.79] is 3.

Here’s the formula:

f = k + [(13*m-1)/5] + D + [D/4] + [C/4] – 2*C.

  • k is the day of the month. Let’s use January 29, 2064 as an example. For this date, k = 29.
  • m is the month number. Months have to be counted specially for Zeller’s Rule: March is 1, April is 2, and so on to February, which is 12. (This makes the formula simpler, because on leap years February 29 is counted as the last day of the year.) Because of this rule, January and February are always counted as the 11th and 12th months of the previous year. In our example, m = 11.
  • D is the last two digits of the year. Because in our example we are using January (see previous bullet) D = 63 even though we are using a date from 2064.
  • C stands for century: it’s the first two digits of the year. In our case, C = 20.

Now let’s substitute our example numbers into the formula.

f = k + [(13*m-1)/5] + D + [D/4] + [C/4] – 2*C
= 29 + [(13*11-1)/5] + 63 + [63/4] + [20/4] – 2*20
= 29 + [28.4] + 63 + [15.75] + [5] – 40
= 29 + 28 + 63 + 15 + 5 – 40
= 100.

Once we have found f, we divide it by 7 and take the remainder.

Note that if the result for f is negative, care must be taken in calculating the proper remainder. Suppose f = -17. When we divide by 7, we have to follow the same rules as for the greatest integer function; namely we find the greatest multiple of 7 less than -17, so the remainder will be positive (or zero). -21 is the greatest multiple of 7 less than -17, so the remainder is 4 since -21 + 4 = -17. Alternatively, we can say that -7 goes into -17 twice, making -14 and leaving a remainder of -3, then add 7 since the remainder is negative, so -3 + 7 is again a remainder of 4.

A remainder of 0 corresponds to Sunday, 1 means Monday, etc. For our example, 100 / 7 = 14, remainder 2, so January 29, 2064 will be a Tuesday.

Common mistakes

The paragraph about negative values of f corrects a common misinterpretation of “remainder”. If you just divided \(-17\) by 7 and got \(-2\frac{3}{7}\), you might think the remainder is 3. One way to avoid this whole issue would be to add 7C to the formula, which doesn’t change the remainder but eliminates any negative terms:

$$f = k + \frac{13m-1}{5} + D + \left[\frac{D}{4}\right] + \left[\frac{C}{4}\right] + 5C$$

Another thing I have observed is that some people confuse remainders with decimals. For example, one student wrote this in 2013 (unarchived):

I was trying to calculate which day of the week my birthday (12/07/1994) fell on. I plugged in all the correct information into Zeller's Formula and I checked my answer against an actual calendar and my answer was wrong. I know for sure that I solved the formula correctly, following all the rules associated with Zeller's Rule, however the outcome was wrong.

Here is the formula including my birth date:

   f=7+[(13*10-1)/5]+94+[94/4]+[19/4]-2*19

I worked this out both by hand and by calculator and my answer was still off by at least four days. Any help you have would be much appreciated. Thank You!

   f=7+[(13*10-1)/5]+94+[94/4]+[19/4]-2*19
   f=7+[(130-1)/5]+94+23+4-2*19
   f=7+[129/5]+94+23+4-2*19
   f=7+25+94+23+4-2*19
   f=2869
   2869/7=409R8

The problem is that a remainder of 8 does not correspond to any day of the week according to the rules for Zeller's Rule.

The “remainder” of 8 was strong evidence that Jacob had divided \(2869\div7=409.8\) and took the tenths place, 8, as the remainder.

I replied:

The last couple steps of your work can't be right. Your value for f is much too large, and the remainder when you divide by 7 can't be greater than 6!

I get this:

  f = 7+25+94+23+4-38 = 115
  115/7 = 16 r 3

My guess is that you didn't follow the order of operations for the first line (that is, you subtracted 2 before multiplying by 19), and that you confused the tenths place of a decimal quotient for the remainder in the second.

One way to get a remainder on a calculator is to first round down the quotient (409.857 --> 409, for your division), and then subtract the quotient times the divisor from the dividend to get the remainder, just as you would in dividing by hand:

       409
    -------
  7 ) 2869
     -2863   <-- 7*409
     -----
         6   <-- remainder

Of course, the correct remainder is

  115 - 7*16 = 115 - 112 = 3

Another common error is just to miss the special rules about January and February.

How does it work?

So how did Zeller come up with the formula? We don’t know for sure. But if we try to derive it ourselves, we might be doing what Zeller did.

Here is a question from 2003:

Deriving Zeller's Rule

I am doing a report on the formula for the day of the week for any day, but I cannot completely figure out how to derive it. How do you derive the formula f=k+[(13*m-1)/5]+d+[d/4]+[c/4]-2*c ?

I answered, first restating the definitions of the variables, which are essential:

Since there are several slightly different formulations of this formula, we'll use the one you are using, from our FAQ:

   The Calendar and the Days of the Week  
   http://mathforum.org/dr.math/faq/faq.calendar.html 

Here we're defining

  k = day of month
  m = month number, taking Mar=1, ..., Dec=10, Jan=11, Feb=12
  d = last two digits of year, using the previous year for Jan and Feb
  c = first two digits of year

The formula is then

  f = k + [(13*m - 1)/5] + d + [d/4] + [c/4] - 2*c

and we use the remainder after dividing f by 7 to find the day of the week.

Having fully stated the theorem, we can prove it.

Where does this come from? Let's first note the reason for the odd handling of months: we want leap day not to affect the formula, so we move it to the end of the 'year', and act as if the year began on March 1.

Now note that in defining f, all we care about is the remainder after dividing, so it will be enough to make sure that f increases by 1 whenever the day of the week advances by one day; we don't care about the actual value of f.

The funny thing is, at one time the year did begin in March, and that is why leap day is at the end of February.

Now let's build the formula piece by piece.

How does the year affect the day? Well, since 365 = 7*52+1, each normal year advances the day by 1, so our formula can start with the year number:

  f = d

Whenever the year advances by 1, so does the day of the week.

But we have to adjust this to account for leap years. Every four years we have an extra day, so we'll want to add 1 to f. This is done by adding [d/4], since this increases by 1 only when d becomes a multiple of 4, which is a leap year. So now we have

  f = d + [d/4]

Now how do centuries affect the day? A century contains 100 years, 24 of which normally are leap years (since century days, like 1900, are NOT leap years). So each century the day advances by 124 days, which is 7*18-2, and therefore the day of the week goes BACK 2 days. So we have

  f = d + [d/4] - 2*c

But every fourth century year IS a leap year (as 2000 was), so we have to adjust just as we did for leap years:

  f = d + [d/4] - 2*c + [c/4]

That handles the entire leap-year part of the Gregorian calendar.

Now we come to the months, and this is the cute part. Consider, for each month, how many days it has BEYOND 28, and then add that up to see the effect the months have on the day of the week:

          1   2   3   4   5   6   7   8   9  10  11  12
  Month  Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb
  Days   31  30  31  30  31  31  30  31  30  31  31  (28)
  Excess  3   2   3   2   3   3   2   3   2   3   3   0
  Accum   0   3   5   8  10  13  16  18  21  23  26  29
         \_________________/\__________________/\_______

The number of accumulated days is counted at the start of the month, so if we divide it by 7, the remainder shows how many weekdays the start of the month is from the starting day for the 'year'.

The “accum” row starts at 0 for the first month, then adds the excess from that month at the start of the next month. Now we want to find a formula for this last row, just as we have done in sequence puzzles. I start as I often do in such puzzles, trying an appropriate multiplier and then seeing what further adjustment will be needed:

Notice the pattern in the excess: 3,2,3,2,3 repeats every five months, and the accumulation reaches 13 in that time. So every 5 months, we want to add 13 days. That suggests that we want to add a term like [13m/5]. That doesn't quite give us what we want:

          1   2   3   4   5   6   7   8   9  10  11  12
  Month  Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb
  Days   31  30  31  30  31  31  30  31  30  31  31  (28)
  Excess  3   2   3   2   3   3   2   3   2   3   3   0
  Accum   0   3   5   8  10  13  16  18  21  23  26  29
  13m    13  26  39  52  65  78  ...
  [13m/5] 2   5   7  10  13  15  ...

If we subtract 2 from this, it isn't quite right; we have to shift it a bit. So after playing with it a bit, we find

  13m-1         12  25  38  51  64  77  ...
  [(13m-1)/5]    2   5   7  10  12  15  ...
  [(13m-1)/5]-2  0   3   5   8  10  13  ...

That's just what we want. So we'll use

  f = d + [d/4] - 2*c + [c/4] + [(13m-1)/5] - 2

This part is basically a lucky accident, based on the (rather messy) way in which the months have ended up being defined. Without that, we’d just have to look up the month in a table, rather than use a neat formula.

Finally, we have to add the day, since each day obviously adds one to the day of the week; and adjust to get the right day of the week for, say, Mar 1, 2000, since nothing we've done so far actually determined WHICH day we start the whole pattern on. It turns out that we can just remove the -2, and we get

  f = d + [d/4] - 2*c + [c/4] + [(13m-1)/5] + k

And there's the formula!

For some information on the history of months, including why the year started in March, and why their names and lengths are strange, see

The Origin of Month Names

Number of Days in a Month

For another derivation of the month part of the formula (by Doctor Rob), see

Formula for the Day of the Month

A different formula

There are other ways to write the rule. Here is a question from 1998, which led to an interesting follow-up question:

Formula for the First Day of a Year

Is there an equation to find the first day of a year if you are given the year?

Doctor Bill answered the more general question, but with a different formula than Doctor Rob’s:

Here is a formula for finding the day of the week for ANY date. 

   N = d + 2m + [3(m+1)/5] + y + [y/4] - [y/100] + [y/400] + 2

where d is the number of the day of the month, m is the number of the month, and y is the year. The brackets around the divisions mean to drop the remainder and just use the integer part that you get.

Also, a VERY IMPORTANT RULE is the number to use for the months for January and February. The numbers of these months are 13 and 14 of the PREVIOUS YEAR. This means that to find the day of the week of New Year's Day this year, 1/1/98, you must use the date 13/1/97. (It sounds complicated, but I will do a couple of examples for you.)

After you find the number N, divide it by 7, and the REMAINDER of that division tells you the day of the week; 1 = Sunday, 2 = Monday, 3 = Tuesday, etc; BUT, if the remainder is 0, then the day is Saturday, that is: 0 = Saturday.

This differs from the FAQ version in having a single number y for the year rather than C and D, and in using the usual month numbers except for January and February. The formula treats months differently in several ways.

As an example, let's check it out on today's date, 3/18/98. Plugging the numbers into the formula, we get;

   N = 18 + 2(3) + [3(3+1)/5] + 1998 + [1998/4] - [1998/100]
       + [1998/400] + 2

So doing the calculations, (remember to drop the remainder for the divisions that are in the brackets) we get;

   N = 18 + 6 + 2 + 1998 + 499 - 19 + 4 + 2 = 2510

Now divide 1510 by 7 and you will get 358 with a remainder of 4. Since 4 corresponds to Wednesday, then today must be Wednesday.

We’d have the same issues with remainder, and with the floor function, that I discussed under the FAQ; but they should show up rarely if at all (can you see why?).

You asked about New Year's Day, so let's look at this year, 1/1/98. Because of the "Very Important Rule," we must use the "date" 13/1/97 to find New Year's Day this year. Plugging into the formula, we get;

   N = 1 + 2(13) + [3(13+1)/5] + 1997 + [1997/4] - [1997/100]
       + [1997/400] + 2

   N = 1+ 26 + 8 + 1997 + 499 - 19 + 4 + 2 = 2518

Now divide 2518 by 7 and look at the remainder: 2518/7 = 359 with a remainder of 5. Since 5 corresponds to Thursday, New Year's Day this year was on a Thursday.

Are they really different?

In 2002, we got the following question about that page (which was appended to it):

Doctor Peterson, 

In your FAQ, you give the following formula for finding the day of the week for a given date:

  f = k + [(13*m-1)/5] + D + [D/4] + [C/4] - 2*C

But in your archive, you give a different formula:

  N = d + 2m + [3(m+1)/5] + y + [y/4] - [y/100] + [y/400] + 2

Obviously these two formulas are equivalent, but I can't see why.  Why the 2m? Why the +2?  Could you be so kind as to explain this equivalence?  I guess I'm trying to understand why the formula works; what is the underlying idea. The 2m and the +2 throw me.

I answered:

The first thing to do is to note the differences:

In the FAQ,

    f = k + [(13*m-1)/5] + D + [D/4] + [C/4] - 2*C

    "m" is the month number starting with March as 1;
    "k" is the day of the month;
    the year is given by C, the century, and D, the last two digits;
    in the result, 0 means Sunday.

In the alternative formula, 

    N = d + 2m + [3(m+1)/5] + y + [y/4] - [y/100] + [y/400] + 2

    "m" is the month number starting with January as 1;
    "y" is the year;
    in the result 0 means Saturday.

It’s easy to miss the different interpretation of the final number.

Now we apply Doctor Bill’s formula to Doctor Rob’s variables:

So if we try to write the latter using the variables of the former, we will have to replace

    d with k
    m with m+2 (so March is 3)
    y with 100C+D
    and subtract 1 from N to get f (so Sunday is 0).

We get

    f = N-1 

      =   k + 2(m+2) + [3((m+2)+1)/5] + (100C+D) + [(100C+D)/4]
        - [(100C+D)/100] + [(100C+D)/400] + 2 - 1

      =   k + 2m + 4 + [3(m+3)/5] + 100C + D + [25C + D/4]
        - [C + D/100] + [C/4 + D/400] + 1

      =   k + 2m + 4 + [3m/5 + 9/5] + 100C + D + 25C + [D/4]
        - C - 0 + [C/4] + 0 + 1

      =   k + [10m/5 + 4 + 3m/5 + 9/5 + 1] + 124C + D + [D/4] + [C/4]

      =   k + [(13m + 4)/5 + 6] + D + [D/4] + [C/4] + 124C

      =   k + [(13m-1)/5 + 7] + D + [D/4] + [C/4] + 124C

This isn't quite right, is it? Unless 

  7 + 124C = -2C, 

it can't be the same.

But … remember I said the actual value of f doesn’t matter, as long as the remainder is right.

The answer is not this whole expression, but the remainder when we divide by 7. The two forms will be the same if

    7 + 124C = -2C (mod 7).

And since 124 = 7*17 + 5 = 7*18 - 2, it is in fact true that the remainder of the left side, 7*(1+18C) - 2C, will be the same as the remainder of -2C. The two formulas are indeed equivalent.

The two formulas’ values of f are not the same, but they always differ by a multiple of 7, so the remainder is always the same.

For another way to find the day of the week, using a table for the months, see

What Day of the Week Was a Given Date?

And the FAQ also shows a method that can be used as a “mental math” trick.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.