156

taxi1010.com

 

 

 

Day of Week Algorithm

157

Day of Week Algorithm


Here's how to calculate the day of the week in your head for any date after September 14, 1752. It's relatively simple once you memorize ten month codes (None needed for April and July). The aim of this algorithm is to produce a single digit in the range 0 to 6. If it's a 0, it's Saturday; otherwise, 1 through 6 stand for Sunday through Friday. The algorithm takes place in seven steps: (1) Divide the last two digits of the year by 2, dropping any remainder. (2) If this result is odd, subtract 3. (3) If the original year is odd, subtract 1. (4) This algorithm is normalized for the 1900s. Add 1 if in or beyond 2000 or 2400 AD; add or subtract 2 for other centuries (no earlier than 9-14-1752). (5) If the result is an even multiple of 7, set it to 0; otherwise, set it to whatever amount is needed to reach the next highest multiple of 7. This final figure is the year-offset, in the range 0 to 6. (6) Add the year-offset, the month code, and the day of month. (7) Divide by 7 and keep only the remainder. That's the day of the week. Don't forget, in leap years — (those years divisible by 4 and not divisible by 100 unless divisible by 400) — in leap years, the codes for January and February are 0 and 3; otherwise they are 1 and 4. Here are two examples ... Good days for a picnic! [Explanation of Algorithm]

 
 

Junio

30, 1947

Feb

24, 1952, a leap year

(1) 47 / 2 = 23

(1) 52 / 2 = 26

(2) 23 - 3 = 20

 

(3) 20 - 1 = 19

 

(5) 19 up to 21 = 2

(5) 26 up to 28 = 2

(6) 2 +

5

+ 30 = 37

(6) 2 +

3

+ 24 = 29

(7) 37 down to 35 = 2

(7) 29 down to 28 = 1

2 = Monday

1 = Sunday

 

mnemonic

month code

(in leap year)

X

1

0

XFeb

4

3

M[arch]

4

--

none

M[ay]

2

Junio

5

--

none

Aug

3

Sep[tember]

6

O

1

Nove

4

De[cember]

6

««

Previous page

 

 

 

Next page

»»