How to determine The day of The week, given The month, day and year?

The information below was lifted from the from the following web site: http://www.cs.uu.nl/wais/html/na-dir/sci-math-faq/dayofweek.html

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 + 400. 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; on many computers this will be less than The instructions to do all The complicated calculations proposed or 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 following frequencies:

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.

In The Mathematical Gazette, vol. 53,, pp.127-129, it is shown that The 13th of The month is more likely to be a Friday than any other day.The author is a 13 year old S.R.Baxter.

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 long!

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 of 400.

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 [This is TRN() in Logix],

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, it returns 0 for Monday, 1 for Tuesday, etc.

dow(m,d,Y){Y-=m<3;return(Y+Y/4-Y/100+Y/400+[m]+d)%7;}

The program appeared was posted by sakamoto@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: 4/4, 6/6, 8/8, 10/10, 12/12 to remember The next four, remember that I work from 9-5 At a 7-11 so 9/5, 5/9, 7/11, 11/7 and The last day of Feb.

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

**References:***Winning Ways for your Mathematical plays. Elwyn R. Berlekamp, John H. Conway, and Richard k. Guy 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*