FANDOM


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 YearsRemaining Year DigitsMonthD
o
W
#
Julian
(r ÷ 7)
Gregorian
(r ÷ 4)
r5 1916 20 r000 06   17 2328 34   45 5156 62   73 7984 90 Jan OctSa0
r4 1815 19 r301 07 12 18 29 35 40 4657 63 68 74 85 91 96 May Su1
r3 17
N/A
02   13 19 2430   41 47 5258   69 75 8086   97 Feb Aug M2
r2 1618 22 r203 08 14   2531 36 42   5359 64 70   8187 92 98Feb Mar NovTu3
r1 15
N/A
  09 15 20 26   37 43 48 54   65 71 76 82   93 99 Jun W4
r0 1417 21 r104 10   21 2732 38   49 5560 66   77 8388 94 Sep DecTh5
r6 13
N/A
05 11 16 2233 39 44 5061 67 72 7889 95 Jan Apr Jul F6

ReferencesEdit

  1. http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html
  2. Wikipedia: Determination of the day of the week

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.