Gregorian Weekday Formula

ss_yo2
Originally Discovered by Leonardo Sembiring
Melialamath Applications. Copyright 2009.

Date : ddmmyyyy.
Split the date into four terms : dd.mm.yy.yy

For example, January 13, 1977.
Split the date into : 13.01.19.77. Therefore, we have four terms : 13, 1, 19, and 77.

Following are the steps to determine the day of the date given :

  1. (First term). The VALUE is the day of the date.
  2. (Second term). To match month of the date into the string 033614625035. The VALUE is the match value.
  3. (Third term). Divided by 4 and multiply the remainder by -2 (minus two). The VALUE is the result of multiplication.
  4. (Fourth term). The VALUE is two right digits of year of the date.
  5. (Fourth term). Divided by 4 (ignore the remainder of the division). The VALUE is the quotient.
  6. (Second term and the year of the date). If month of the date falls in JANUARY or FEBRUARY, there are 3 (three) additional sequence checks. If the answer of current check is YES, then the next check will not be carried on. The corresponded values are -1, 0, -1 respectively for each check.
    • Check year of the date, is multiple of 400?. If YES, no further checking. The value is -1 (minus one). If NO, continue to the next checking.
    • Check year of the date, is multiple of 100?. If YES, no further checking. The value is 0 (zero). If NO, continue to the next checking.
    • Check year of the date, is multiple of 4?. If YES, the value is -1 (minus one). If NO, the value is 0 (zero).

The FINAL VALUE is the total value of step 1 through 6, modulo 7 (7-basis). Refer to the table below to determine the weekday of the date.

Final Value Weekday
0 Saturday
1 Sunday
2 Monday
3 Tuesday
4 Wednesday
5 Thursday
6 Friday


Example 1 :
January 13, 1977
The format is 13.01.19.77. So, there are four terms : 13, 1, 19, and 77.

Here are the steps :
Step 1 : The day, 13.
Step 2 : The month is 1, the 1st character in ‘033614625035’ is 0.
Step 3 : Third term, 19 divided by 4, the remainder is 3. And 3 times (-2) is -6.
Step 4 : Two right digits of year or fourth term, 77.
Step 5 : Fourth term, 77 divided by 4. The quotient is 19.
Step 6 : Month is January. Is 1977 multiple of 400? No. Is 1977 multiple of 100? No. Is 1977 multiple of 4? No. Then, the value is 0.

The final value is 13 + 0 + (-6) + 77 + 19 + 0 = 103 modulo 7 = 5 (Thursday).

Example 2 :
May 27, 1970
The format is 27.05.19.70. So, there are four terms : 27, 5, 19, and 70.

Here are the steps :
Step 1 : The day, 27.
Step 2 : The month is 5, the 5th character in ‘033614625035’ is 1.
Step 3 : Third term, 19 divided by 4, the remainder is 3. And 3 times (-2) is -6.
Step 4 : Two right digits of year or fourth term, 70.
Step 5 : Fourth term, 70 divided by 4. The quotient is 17.
Step 6 : Month is not January or February. Not executed.

The final value is 27 + 1 + (-6) + 70 + 17 = 109 modulo 7 = 4 (Wednesday).

Example 3 :
February 12, 2200
The format is 12.02.22.00. So, there are four terms : 12, 2, 22, and 0.

Here are the steps :
Step 1 : The day, 12.
Step 2 : The month is 2, the 2nd character in ‘033614625035’ is 3.
Step 3 : Third term, 22 divided by 4, the remainder is 2. And 2 times (-2) is -4.
Step 4 : Two right digits of year or fourth term, 0.
Step 5 : Fourth term, 0 divided by 4. The quotient is 0.
Step 6 : Month is February. Is 2200 multiple of 400? No. Is 2200 multiple of 100? Yes. Then, the value is 0.

The final value is 12 + 3 + (-4) + 0 + 0 + 0 = 11 modulo 7 = 4 (Wednesday).

Example 4 :
January 21, 2400
The format is 21.01.24.00. So, there are four terms : 21, 1, 24, and 0.

Here are the steps :
Step 1 : The day, 21.
Step 2 : The month is 1, the 1st character in ‘033614625035’ is 0.
Step 3 : Third term, 24 divided by 4, the remainder is 0. And 0 times (-2) is 0.
Step 4 : Two right digits of year or fourth term, 0.
Step 5 : Fourth term, 0 divided by 4. The quotient is 0.
Step 6 : Month is January. Is 2400 multiple of 400? Yes. Then, the value is -1.

The final value is 21 + 0 + 0 + 0 + 0 + (-1) = 20 modulo 7 = 6 (Friday).

Example 5 :
February 11, 2112
The format is 11.02.21.12. So, there are four terms : 11, 2, 21, and 12.

Here are the steps :
Step 1 : The day, 11.
Step 2 : The month is 2, the 2nd character in ‘033614625035’ is 3.
Step 3 : Third term, 21 divided by 4, the remainder is 1. And 1 times (-2) is -2.
Step 4 : Two right digits of year or fourth term, 12.
Step 5 : Fourth term, 12 divided by 4. The quotient is 3.
Step 6 : Month is February. Is 2112 multiple of 400? No. Is 2112 multiple of 100? No. Is 2112 multiple of 4? Yes. Then, the value is -1.

The final value is 11 + 3 + (-2) + 12 + 3 + (-1) = 26 modulo 7 = 5 (Thursday).

Have a nice day!
Leonardo Sembiring

Notes :
This documentation is firstly published on 24 September 2009. It has been checked against Excel function WEEKDAY, and the results are precisely the same.

Advertisements