## Day number from dateEdit

This formula determines the "day" number of a given day.^{[1]} Note that the formula uses March 1, 1CE as the anchor point.

All math in the algorithm shown is integer arithmetic.

function g(y,m,d): m = (m + 9) % 12 y = y - m/10 return 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 )

Reversing this:

function d(g) y = (10000*g + 14780)/3652425 ddd = g - (365*y + y/4 - y/100 + y/400) if (ddd < 0) then y = y - 1 ddd = g - (365*y + y/4 - y/100 + y/400) endif mi = (100*ddd + 52)/3060 mm = (mi + 2)%12 + 1 y = y + (mi + 2)/12 dd = ddd - (mi*306 + 5)/10 + 1 return y, mm, dd

## Day of the weekEdit

### SubtractionEdit

Determining the day of the week can be obtained by taking a known value (e.g. Wednesday January 1, 1800), getting the number of days between the desired date and the anchor, and using modular arithmetic.

If using the day number from date algorithm above, simply add 3 to the return value, and modulus by 7 to get the day of the week (0=sunday, 1=monday...)

### Mental calculationEdit

Although there is a simple formula, it requires the use of lookup tables.^{[2]}

- w = (d + m + y + floor(y/4) + c) mod 7
- d = day of month
- m = month's number
- y = last two digits of the year
- c = century number.

The century and month's number are obtained from the table below. The bold numbers in they year's digits signify leap years. If the last two digits are "00", it's a leap year only if the the 100s of years colum is bold.

In the month section, the bold **Jan** and **Feb** are used only for leap years.

100s of Years | Remaining Year Digits | Month | D o W | # | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|

Julian (r ÷ 7) | Gregorian (r ÷ 4) | |||||||||||

r5 19 | 16 20 r0 | 00 06 17 23 | 28 34 45 51 | 56 62 73 79 | 84 90 | Jan | Oct | Sa | 0 | |||

r4 18 | 15 19 r3 | 01 07 12 18 | 29 35 40 46 | 57 63 68 74 | 85 91 96 | May | Su | 1 | ||||

r3 17 | 02 13 19 24 | 30 41 47 52 | 58 69 75 80 | 86 97 | Feb | Aug | M | 2 | ||||

r2 16 | 18 22 r2 | 03 08 14 25 | 31 36 42 53 | 59 64 70 81 | 87 92 98 | Feb | Mar | Nov | Tu | 3 | ||

r1 15 | 09 15 20 26 | 37 43 48 54 | 65 71 76 82 | 93 99 | Jun | W | 4 | |||||

r0 14 | 17 21 r1 | 04 10 21 27 | 32 38 49 55 | 60 66 77 83 | 88 94 | Sep | Dec | Th | 5 | |||

r6 13 | 05 11 16 22 | 33 39 44 50 | 61 67 72 78 | 89 95 | Jan | Apr | Jul | F | 6 |