Drexel dragonThe Math ForumDonate to the Math Forum

Ask Dr. Math - Questions and Answers from our Archives
_____________________________________________
Associated Topics || Dr. Math Home || Search Dr. Math
_____________________________________________

Deriving Zeller's Rule

Date: 02/25/2003 at 23:09:20
From: Coby
Subject: How do you derive the formula for the day of the week?

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 ?


Date: 02/26/2003 at 09:11:15
From: Doctor Peterson
Subject: Re: How do you derive the formula for the day of the week?

Hi, Coby.

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.

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.

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]

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'.

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

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 more details on the origin of the formula, see

   Calendrical Works of Rektor Chr. Zeller
   http://www.merlyn.demon.co.uk/zeller-c.htm#ZC 

If you have any further questions, feel free to write back.

- Doctor Peterson, The Math Forum
  http://mathforum.org/dr.math/ 


Date: 02/26/2003 at 21:23:26
From: Coby
Subject: Thank you (How do you derive the formula for the day of the 
week?)

Thank you so much! Your answer was realy helpful and detailed. Thank 
you!
Associated Topics:
Middle School Calendars/Dates/Time

Search the Dr. Math Library:


Find items containing (put spaces between keywords):
 
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

_____________________________________
Math Forum Home || Math Library || Quick Reference || Math Forum Search
_____________________________________

Ask Dr. MathTM
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/