How to determine the day of the week, given the month, day and year
First a brief explanation: In the Gregorian Calendar, over a period of
four hundred years, there are 97 leap years and 303 normal years. Each
normal year, the day of January 1 advances by one; for each leap year
it advances by two.
303 + 97 + 97 = 497 = 7 * 71
As a result, January 1 year N occurs on the same day of the week as
January 1 year N + 4004 . Because the leap year pattern also recurs
with a four hundred year cycle, a simple table of four hundred
elements, and single modulus, suffices to determine the day of the
week (in the Gregorian Calendar), and does it much faster than all the
other algorithms proposed. Also, each element takes (in principle)
only three bits; the entire table thus takes only 1200 bits, or 300
bytes; on many computers this will be less than the instructions to do
all the complicated calculations proposed for the other algorithms.
Incidental note: Because 7 does not divide 400, January 1 occurs more
frequently on some days than others! Trick your friends! In a cycle of
400 years, January 1 and March 1 occur on the following days with the
Sun Mon Tue Wed Thu Fri Sat
Jan 1: 58 56 58 57 57 58 56
Mar 1: 58 56 58 56 58 57 57
Of interest is that (contrary to most initial guesses) the occurrence
is not maximally flat.
The Gregorian calendar was introduced in 1582 in parts of Europe; it
was adopted in 1752 in Great Britain and its colonies, and on various
dates in other countries. It replaced the Julian Calendar which has a
four-year cycle of leap years; after four years January 1 has advanced
by five days. Since 5 is relatively prime to 7, a table of 4 * 7 = 28
elements is necessary for the Julian Calendar.
There is still a 3 day over 10,000 years error which the Gregorian
calendar does not take into account. At some time such a correction
will have to be done but your software will probably not last that
Here is a standard method suitable for mental computation:
1. Take the last two digits of the year.
2. Divide by 4, discarding any fraction.
3. Add the day of the month.
4. Add the month's key value: JFM AMJ JAS OND 144 025 036 146
5. Subtract 1 for January or February of a leap year.
6. For a Gregorian date, add 0 for 1900's, 6 for 2000's, 4 for
1700's, 2 for 1800's; for other years, add or subtract multiples
7. For a Julian date, add 1 for 1700's, and 1 for every additional
century you go back.
8. Add the last two digits of the year.
9. Divide by 7 and take the remainder.
Now 1 is Sunday, the first day of the week, 2 is Monday, and so on.
The following formula, which is for the Gregorian calendar only, may
be more convenient for computer programming. Note that in some
programming languages the remainder operation can yield a negative
result if given a negative operand, so mod 7 may not translate to a
simple remainder. W = (k + floor(2.6m - 0.2) - 2C + Y + floor(Y/4) +
floor(C/4)) mod 7 where floor() denotes the integer floor function,
k is day (1 to 31)
m is month (1 = March, ..., 10 = December, 11 = Jan, 12 = Feb) Treat
Jan &Feb as months of the preceding year
C is century (1987 has C = 19)
Y is year (1987 has Y = 87 except Y = 86 for Jan &Feb)
W is week day (0 = Sunday, ..., 6 = Saturday)
Here the century and 400 year corrections are built into the formula.
The floor(2.6m - 0.2) term relates to the repetitive pattern that the
30-day months show when March is taken as the first month.
The following short C program works for a restricted range
The program appeared was posted by saka...@sm.sony.co.jp (Tomohiko
Sakamoto) on comp.lang.c on March 10th, 1993.
A good mnemonic rule to help on the computation of the day of the week
is as follows. In any given year the following days come on the same
day of the week:
to remember the next for remember that I work from 9-5 at a 7-11 so
and the last day of Feb.
This year they come on a Monday. Every year this advances one (so next
year they come on a Tuesday) other than leap-years which advance 2.
Thus every 4 years it advances 5 days (there is one more minor
correction at the century mark).
Even ignoring the pattern over for a period of years this is still
useful since you can generally figure out what day of the week a given
date is on faster than someone else can look it up with a calender if
the calender is not right there. (A useful skill that.)
Winning Ways for your mathematical plays. Guy Conway and Elwyn
Berlekamp London ; Toronto : Academic Press, 1982.
Mathematical Carnival. Martin Gardner. New York : Knopf, c1975.
Elementary Number Theory and its applications. Kenneth Rosen. Reading,
Mass. ; Don Mills, Ont. : Addison-Wesley Pub. Co., c1993. p. 156.
Michael Keith and Tom Craver. The Ultimate Perpetual Calendar? Journal
of Recreational Mathematics, 22:4, pp. 280-282, 19
Sun Nov 20 20:45:48 EST 1994
An easy system to determine the day of the week by mental arithmetic
In the beginning of 1967 I read in a book "Trivsamma Tidsfördriv"
(I cannot remember the author) about the month´s key value:
JFMA MJJA SOND 1440 2503 6146( I like it this way because it is easy to
learn by heart)
If you choose 1 for January and if you want to add "the day of the month"
to 1 and to some basic day and if you want to start at an even year that
is not a leap-year you may choose 1950 and the basic day to Friday.
The 1st of January 1950 was a Sunday (Friday+1+1=Sunday).It is 31 days in
January and as after seven days you will receive the same day again you
can take away 7x4=28 days from 31 and you will have 3 days more in February
than in January. I.e. february gets 1+3=4 and so on. April gets 7 which is
the same as 0.
Now it is easy to count any day in 1950. For example: 27th of September:
Friday+6+27=Friday+33=Friday+7x4+5=Friday+5=Wednesday (or =Friday+5x7-2=
The year has 365 days and 365-52x7=1 i.e. the basic day for 1951 is
Saturday. Adding one year = adding one day (to the basic day). Till now I
am telling you about the information that was given in the book.
Now I started to analyse how to go quickly to other years. In this time
there were no minicalculators and I wanted to get a system easy to use
with mental calculation and with only the 12 above mentioned month´s key
values learnt by heart.
However how can I jump. I found that starting from 1950 (or from a year
that is not a leap-year) after moving 4 years you always
have to go (5 days in the same direction or) 2 days in the opposite
direction.1954 basic day is a Wednesday (Friday+5 or as I use when
I calculate Friday-2. 1946 basic day is a Sunday (Friday-5 or Friday+2).
I also found that starting from 1950 (or another year that is not
a leap-day) after 4x7xn=28xn (where n is an integer) days you will
receive the same basic day.
Starting from 1950 (or another even year that is not a leap-year)
after 17 or 11 days you will also get the same basic day.
I also found some other rules but in practice the above mentioned rules
are enough if you want to calculate any day ( If you add more rules
you will probably forget them.) with the following to remember:
In the leap-year 1952 January and February has the basic day Sunday and
March-December has the basic day Monday. All leap-years have two basic days
in the same style as 1952.
In the Gregorian calendar the years 1900, 1800, 1700 where not leap-years
but the year 1600 was and the year 2000 will be a leap-years. Therefore
you have to add nothing for 1900´s and 2000´s but you have to
add 1 for 1800´s, 2 for 1700´s, 3 for 1600´s and for 1500´s.
For whole Julian calendar you have to take away (subtract) 1.
Examples: In all these exemples I show how to use very simple mental
arithmetic if you want to give a performance with no other preparations
than just reading this letter.
1. 3rd of December 1939
1950=Friday, 1939=Friday (-11 is the same year).Friday+3+6=Friday+2=Sunday
2. 1st of January 2000
1950=Friday, 1978=Friday (28 years).1995=Friday (17 years).
1999=Wednesday (+4 years"="-2 days), 2000 jan-feb =Tuesday (+ 1 year=+1 day)
Tuesday+1+1=Saturday (Friday and Saturday seems to be good day to celebrate
the new millennium)
3. 17th of December 1888
1950=Friday, 1894=Friday (1950-2x28), 1890=Sunday( -4 years,+2 days),
1889=Saturday, 1888(mar-dec)=Friday, but it is 1800´s and we have to add 1.
So 1888(mar-dec)=Saturday. Saturday+17+6=Saturday+23=Saturday+2=Monday
4. 14th of July 1789
1950=Friday, 1810=Friday (1950-28x5),1793=Friday (1810-17), 1789=Sunday
(- 4 years, +2 days). It is 1700´s and we have to add 2. 1789=Tuesday.
5. 5th of January 1591, Julian Calendar (We are in Great Britain or in
1950=Friday, 1670=Friday (1950-10x28),1586=Friday (1670-3x28),
1590=Wednesday (+4 years, -2 days), 1591=Thirsday.
It is the Julian Calendar and we have to take away 1. So 1591=Wednesday.
I have used this system many times just as fun using mental calculation and
I have not trained myself to be quick. For example it is possible to add
a lot of extra rules to get quicker. People will still be impressed even
if it takes some time to count.
e-mail address: tommy....@lemes.se
An easy system to determine the day of the week, correction
Unfortunately I have found and error in my letter. Two times I wrote
days instead of years. The lines 29-33 must be:
I also found that starting from 1950 (or another year that is not
a leap-day) after adding or subtracting 4 x 7 x n = 28 x n (where n is
an integer) years you will receive the same basic day.
Starting from 1950 (or another even year that is not a leap-year) after
adding or subtracting 17 or 11 years you will also get the same basic day.
I am sorry