Determination of the day of the week

From Infogalactic: the planetary knowledge core
Jump to: navigation, search

There are various methods to calculate the day of the week for any particular date in the past or future. These methods ultimately rely on algorithms to determine the day of the week for any given date, including those based solely on tables as found in perpetual calendars that require no calculations to be performed by the user. A typical application is to calculate the day of the week on which someone was born or any other specific event occurred.

Introduction

To determine the day of the week from numerical operations, Sunday through Saturday are represented as numbers which may, corresponding to Sunday being the first day of the week, be 1 to 7 (or 0, rejecting whole sevens) respectively, which is equivalent to ISO 8601's alternative usage of 1 = Monday to 7 = Sunday). This is achieved with arithmetic modulo 7. Modulo 7 is an operation that calculates the remainder of a number being divided by 7. Thus the number 7 is treated as 0, 8 as 1, 9 as 2, 18 as 4 and so on; the interpretation of this being that if Sunday is signified as day 1, then 7 days later (i.e. day 8) is also a Sunday, and day 18 will be the same as day 4, which is a Wednesday since this falls three days after Sunday.

Standard Monday Tuesday Wednesday Thursday Friday Saturday Sunday Usage examples
ISO 8601 1 2 3 4 5 6 7  %_ISODOWI%, %@ISODOWI[]% (4DOS);[1] DAYOFWEEK() (HP Prime)[2]
0 1 2 3 4 5 6
2 3 4 5 6 7 1 %NDAY OF WEEK% (NetWare, DR-DOS[3]); %_DOWI%, %@DOWI[]% (4DOS)[1]
1 2 3 4 5 6 0 HP financial calculators

The basic approach of nearly all of the methods to calculate the day of the week begins by starting from an ‘anchor date’: a known pair (such as January 1, 1800 as a Wednesday), determining the number of days between the known day and the day that you are trying to determine, and using arithmetic modulo 7 to find a new numerical day of the week.

One standard approach is to look up (or calculate, using a known rule) the value of the first day of the week of a given century, look up (or calculate, using a method of congruence) an adjustment for the month, calculate the number of leap years since the start of the century, and then add these together along with the number of years since the start of the century, and the day number of the month. Eventually, one ends up with a day-count to which one applies modulo 7 to determine the day of the week of the date.[4]

Some methods do all the additions first and then cast out sevens, whereas others cast them out at each step, as in Lewis Carroll's method. Either way is quite viable: the former is easier for calculators and computer programs; the latter for mental calculation (it is quite possible to do all the calculations in one's head with a little practice). None of the methods given here perform range checks, so that unreasonable dates will produce erroneous results.

Useful concepts

Corresponding months

"Corresponding months" are those months within the calendar year that start on the same day. For example, September and December correspond, because 1 September falls on the same day as 1 December. Months can only correspond if the number of days between their first days is divisible by 7, or in other words, if their first days are a whole number of weeks apart. For example, February of a year which is not a leap year corresponds to March because February has 28 days, a number divisible by 7, 28 days being exactly four weeks. In a leap year, January and February correspond to different months than in a common year, since adding 29 February means each subsequent month starts a day later.

The months correspond thus:
For common years:

  • January and October.
  • February, March and November.
  • April and July.
  • No month corresponds to August.

For leap years:

  • January, April and July.
  • February and August.
  • March and November.
  • No month corresponds to October.

For all years:

  • September and December.
  • No month corresponds to May or June.

In the months table below, corresponding months have the same number, a fact which follows directly from the definition.

Corresponding years

There are seven possible days that a year can start on, and leap years will alter the day of the week after February 29. This means that there are 14 configurations that a year can have. All the configurations can be referenced by a Dominical letter, but as 29 February has no letter allocated to it a leap year has two dominical letters, one for January and February and the other (one step back in the alphabetical sequence) for March to December. For example, 2016 is a leap year starting on Friday, meaning that the first two months of the year begin on the same day as they do in 2010 (i.e. 1 January is on a Friday and 1 February is on a Monday) but because of a leap day the last ten months correspond to the last ten months in 2011 (i.e. 1 March is on a Tuesday, etc.). 2017, on the other hand, is a common year starting on Sunday, meaning that 2017 corresponds to the calendar year 2006.

A tabular method to calculate the day of the week

Basic method for mental calculation

This method is valid for both the Gregorian calendar and the Julian calendar. Britain and its colonies started using the Gregorian calendar on Thursday, September 14, 1752; the previous day was Wednesday, September 2, 1752 (old style). The areas now forming the United States adopted the calendar at different times depending on the colonial power: Spain and France had been using it since 1582, while Russia was still using the Julian calendar when Alaska was purchased from it in 1867.

The formula is \left(d + m + y + \left\lfloor\frac{y}{4}\right\rfloor + c\right) \bmod 7, where:

  • d is the day of the month,
  • m is the month's number in the months table
  • y is the last two digits of the year, and
  • c is the century's number in the "100s of Years" table.

If the result is 0, the date was a Saturday; if 1 it was a Sunday, and so on through the week until 6 = Friday.

For the Gregorian date of January 1, 2000 (a leap year):

  • The day of the month: 1
  • January in the months table: 6
  • Last two digits of year: 0
  • Last two digits of year divided by 4: 0
  • Century number: 0

The result is 7, leaving a remainder of 0 when divided by 7, so January 1, 2000 was a Saturday.

For the Julian date of October 13, 1307:

  • The day of the month: 13
  • October in the months table: 0
  • Last two digits of year: 7
  • Last two digits of year divided by 4: 1
  • Century number: 6

The result is 27, leaving a remainder of 6 when divided by 7, so October 13, 1307 was a Friday.

Complete table: Julian and Gregorian calendars

For Julian dates before 1300 and after 1999 the year in the table which differs by an exact multiple of 700 years should be used. For Gregorian dates after 2299, the year in the table which differs by an exact multiple of 400 years should be used. The values "r0" through "r6" indicate the remainder when the Hundreds value is divided by 7 and 4 respectively, indicating how the series extend in either direction. Both Julian and Gregorian values are shown 1500–1999 for convenience. Bold figures (e.g., 04) denote leap year. If a year ends in 00 and its hundreds are in bold it is a leap year. Thus 19 indicates that 1900 is not a Gregorian leap year, (but 19 in the Julian column indicates that it is a Julian leap year, as are all Julian x00 years). 20 indicates that 2000 is a leap year. Use Jan and Feb only in 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
N/A
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
N/A
  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
N/A
05 11 16 22 33 39 44 50 61 67 72 78 89 95 Jan Apr Jul F 6

For determination of the day of the week (1 January 2000, Saturday)

  • the day of the month: 1 ~ 31 (1)
  • the month: (6)
  • the year: (0)
  • the century mod 4 for the Gregorian calendar and mod 7 for the Julian calendar (0).
  • adding 1+6+0+0=7. Dividing by 7 leaves a remainder of 0, so the day of the week is Saturday.

The formula is w = (d + m + y + c) mod 7.

Revised Julian calendar

Note that the date (and hence the day of the week) in the Revised Julian and Gregorian calendars is the same from 14 October 1923 to 28 February AD 2800 inclusive and that for large years it may be possible to subtract 6300 or a multiple thereof before starting so as to reach a year which is within or closer to the table.

To look up the weekday of any date for any year using the table, subtract 100 from the year, divide the difference by 100, multiply the resulting quotient (omitting fractions) by seven and divide the product by nine. Note the quotient (omitting fractions). Enter the table with the Julian year, and just before the final division add 50 and subtract the quotient noted above.

Example: What is the day of the week of 27 January 8315?

8315-6300=2015, 2015-100=1915, 1915/100=19 remainder 15, 19x7=133, 133/9=14 remainder 7. 2015 is 700 years ahead of 1315, so 1315 is used. From table: for hundreds (13): 6. For remaining digits (15): 4. For month (January): 0. For date (27): 27. 6+4+0+27+50-14=73. 73/7=10 remainder 3. Day of week = Tuesday.

Sunday Letter

To find the Sunday Letter, calculate the day of the week for either 1 January or 1 October. If it is Sunday, the Sunday Letter is A, if Saturday B, and similarly backwards through the week and forwards through the alphabet to Monday, which is G.

Leap years have two Sunday Letters, so for January and February calculate the day of the week for 1 January and for March to December calculate the day of the week for 1 October.

Leap years are all years which divide exactly by four with the following exceptions:

In the Gregorian calendar – all years which divide exactly by 100 (other than those which divide exactly by 400).

In the Revised Julian calendar – all years which divide exactly by 100 (other than those which give remainder 200 or 600 when divided by 900).

Week table

Step 1: find the day name (Sun to Sat) of the intersection of the month row and the date column (1 to 7).

Step 2: find the column in which the day name is located in the year row.

Step 3: find the day name of the intersection of century row and the column to determine the day of the week.

Date 01 02 03 04 05 06 07
08 09 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
Month 29 30 31 Year modulo 28 Century mod 4 Century mod 7
4 07 Sun Mon Tue Wed Thu Fri Sat 01 07 12 18 24 160 20 0 05 012 5
9 012 Sat Sun Mon Tue Wed Thu Fri 02 08 13 19 24 06 013 6
6 Fri Sat Sun Mon Tue Wed Thu 03 08 14 20 25 17 021 1 07 014 0
20 3 011 Thu Fri Sat Sun Mon Tue Wed 04 09 15 20 26 080 15 1
8 Wed Thu Fri Sat Sun Mon Tue 04 10 16 21 27 18 022 2 09 002 2
5 Tue Wed Thu Fri Sat Sun Mon 05 11 16 22 00 100 03 3
10 10 Mon Tue Wed Thu Fri Sat Sun 06 12 17 23 00 19 023 3 11 004 4

For determination of the day of the week (January 1, 2000, Saturday)

  • the day of the month: 1 ~ 31 (1)
  • the month: 1 for January ~ 12 for December (1,Mon)
  • the year: 00 ~ 99 mod 28 and italic for January or February in leap years (00 ~ Mon)
  • the century mod 4 for the Gregorian calendar and mod 7 for the Julian calendar (20 or 0 ~ Sat).

For determination of the dominical letter of a year (2100 C ~ 2199 F)

  • the century column: from the century row to Sun which is in the column and in the row (21 or 1)
  • the dominical letter: Mon for A ~ Sun for G from the year row to the century column (00 ~ Wed for C, 15 for 99 ~ Sat for F).

Gauss's algorithm

In a handwritten note in a collection of astronomical tables, Carl Friedrich Gauss described a method for calculating the day of the week for 1 January in any given year.[5] He never published it. It was finally included in his collected works in 1927.[6]

Gauss' Method was applicable to the Gregorian calendar. He numbered the weekdays from 0 to 6 starting with Sunday. He defined the following operation: The weekday of 1 January in year number A is[5]

 R(1 + 5R(A-1,4) + 4R(A-1,100) + 6R(A-1,400),7)

where R(y,m) is the remainder after division of y by m,[6] or y modulo m.

This formula was also converted into graphical and tabular methods for calculating any day of the week by Kraitchik and Schwerdtfeger.[6][7]

Formulas derived from Gauss' algorithm

Gauss' algorithm for January 1 can be converted into methods for calculating the day of the week for any given date as follows.

  • For the Gregorian calendar
    Let A − 1 = year = Y, m = month − 2 mod 12 (March = 1,..., January = −1 mod 12 = 11 and February = 12) and d = days of the month, this formula becomes
     w = d + \lfloor 2.6m - 0.2 \rfloor + 5R(Y,4) + 4R(Y,100) + 6R(Y,400) \bmod 7.
    Let A − 1 = year = y + 100c, this formula becomes
     w = d + \lfloor 2.6m - 0.2 \rfloor + 5R(y,4) + 3R(y,7) + 5R(c,4) \bmod 7.
  • For the Julian calendar
     w = d + \lfloor 2.6m - 0.2 \rfloor + 5R(Y,4) + 3R(Y,7) \bmod 7
     w = d + \lfloor 2.6m - 0.2 \rfloor + 5R(y,4) + 3R(y,7) + 6R(c,7) \bmod 7
  • Note: year − 1 for January and February.
    For January 1, 2000, the date would be treated as the 11th month of 1999,
    d = 1
    [2.6 × 11 − 0.2] = 28 mod 7 = 0
    5R(99,4) = 5 × 3 = 15 mod 7 = 1
    4R(1999,100) = 4 × 99 mod 7 = 4 × 1 = 4
    6R(1999,400) = 6 × 399 mod 7 = 6 × 0 = 0
    3R(99,7) = 3 × 1 = 3
    5R(19,4) = 5 × 3 mod 7 = 1
    w = 1 + 0 + 1 + 4 + 0 = 1 + 0 + 1 + 3 + 1 = 6 = Saturday.
    For December 31, 2000, the date would be treated as the 10th month of the year,
    d = 31 mod 7 = 3
    [2.6 × 10 − 0.2] = 25 mod 7 = 4
    5R(00,4) = 5 × 0 = 0
    4R(2000,100) = 4 × 0 = 0
    6R(2000,400) = 6 × 0 = 0
    3R(00,7) = 3 × 0 = 0
    5R(20,4) = 5 × 0 = 0
    w = 3 + 4 + 0 + 0 + 0 = 3 + 4 + 0 + 0 + 0 = 7 mod 7 = 0 = Sunday.
    For April 30, 1777, the date would be treated as the second month of the year,
    d = 30 mod 7 = 2
    [2.6 × 2 − 0.2] = 5
    5R(77,4) = 5 × 1 = 5
    4R(1777,100) = 4 × 77 mod 7 = 0
    6R(1777,400) = 6 × 177 mod 7 = 6 × 2 mod 7 = 5
    3R(77,7) = 3 × 0 = 0
    5R(17,4) = 5 × 1 = 5
    w = 2 + 5 + 5 + 0 + 5 = 17 mod 7 = 3 = Wednesday.
    For October 4, 1582, the date would be treated as the 8th month of the year,
    d = 4
    [2.6 × 8 – 2.2] = 4
    5R(82,4) = 5 × 2 mod 7 = 3
    3R(1582, 7) = 3 × 0 = 0
    3R(82,7) = 3 × 5 mod 7 = 1
    6R(15,7) = 6 × 1 = 6
    w = 4 + 4 + 3 + 0 mod 7 = 4 + 4 + 3 + 1 + 6 mod 7 = 4 = Thursday.
    For January 1, 0 (BC 1), the date would be treated as the 11th month of the previous year,
    d = 1
    [2.6 × 11 – 2.2] = 5
    5R(−1,4) = 5 × 3 mod 7 = 1
    3R(−1,7) = 3 × 6 mod 7 = 4
    3R(−1,7) = 3 × 6 mod 7 = 4
    6R(0,7) = 6 × 0 = 0
    w = 1 + 5 + 1 + 4 mod 7 = 1 + 5 + 1 + 4 + 0 mod 7 = 4 = Thursday.

Disparate variation

Another variation of the above algorithm likewise works with no lookup tables. A slight disadvantage is the unusual month and year counting convention. The formula is

w = \left(d + \lfloor 2.6m - 0.2 \rfloor + y + \left\lfloor\frac{y}{4}\right\rfloor + \left\lfloor\frac{c}{4}\right\rfloor - 2c\right) \bmod 7,

where

  • Y is the year minus 1 for January or February, and the year for any other month
  • y is the last 2 digits of Y
  • c is the first 2 digits of Y
  • d is the day of the month (1 to 31)
  • m is the shifted month (March=1,...,February=12)
  • w is the day of week (0=Sunday,...,6=Saturday)

For example, January 1, 2000. (year − 1 for January)

<templatestyles src="Div col/styles.css"/>

\begin{align} w &= \left(1 + \lfloor 2.6 \cdot 11 - 0.2 \rfloor + (0 - 1) + \left\lfloor\frac{0 - 1}{4}\right\rfloor + \left\lfloor\frac{20}{4}\right\rfloor - 2 \cdot 20\right) \bmod 7 \\ &= (1 + 28 - 1 -1 + 5 - 40) \bmod 7 \\ &= 6 = \text{Saturday} \end{align}

\begin{align} w &= \left(1 + \lfloor 2.6 \cdot 11 - 0.2 \rfloor + (100 - 1) + \left\lfloor\frac{100 - 1}{4}\right\rfloor + \left\lfloor\frac{20 - 1}{4}\right\rfloor - 2 \cdot (20 - 1)\right) \bmod 7 \\ &= (1 + 28 +99 + 24 + 4 - 38) \bmod 7 \\ &= 6 = \text{Saturday} \end{align}

Note: The first is only for a 00 leap year and the second is for any 00 years.

The term ⌊2.6m − 0.2⌋ mod 7 gives the values of months: m

Months                m
January               0
February              3 
March                 2
April                 5
May                   0
June                  3
July                  5
August                1
September             4
October               6
November              2
December              4

The term y + ⌊y/4⌋ mod 7 gives the values of years: y

y mod 28              y
01 07 12 18 –-        1
02 -– 13 19 24        2
03 08 14 –- 25        3
-- 09 15 20 26        4
04 10 –- 21 27        5
05 11 16 22 –-        6
06 -– 17 23 00        0

The term c/4⌋ − 2c mod 7 gives the values of centuries: c

c mod 4               c   
1                     5
2                     3
3                     1
0                     0

Now from the general formula: w = d + m + y +c \bmod 7; January 1, 2000 can be recalculated as follows:

<templatestyles src="Div col/styles.css"/>

\begin{align} w &= 1 + 0 + 5 + 0 \bmod 7 = 6 = \text{Saturday}\\ d &= 1, m = 0\\ y &= 5 (0 - 1 \bmod 28 = 27)\\ c &= 0 (20 \bmod 4 = 0) \end{align}

\begin{align} w &= 1 + 0 + 4 + 1 \bmod 7 = 6 = \text{Saturday}\\ d &= 1, m = 0\\ y &= 4 (99 \bmod 28 = 15)\\ c &= 1 (20 - 1 \bmod 4 = 3) \end{align}

Kraitchik's variation

Kraitchik proposed two methods for calculating the day of the week.[7] One is a graphical method. The other uses a formula that he credits to Gauss on p. 110:

w = d + m + c + y \bmod 7,

where w is the day of the week (counting upwards from 1 on Sunday instead of 0 in Gauss's version); and d, m, c and y are numbers depending on the day, month, and year as in the following tables:

Month 1 2 3 4 5 6 7 8 9 10 11 12
m 1 4 3 6 1 4 6 2 5 0 3 5

For the Gregorian calendar, take the century of the year (example, the year 1986 would be 1900, 2014 would be 2000).

⌊Century/100⌋ mod 4 0 1 2 3
c 0 5 3 1

For the Julian calendar,

⌊Century/100⌋ mod 7 0 1 2 3 4 5 6
c 5 4 3 2 1 0 6

Finally, the year number is obtained from this table (with 1 being subtracted from dates in January or February):

Last two digits of the year y
00 06 17 23 28 34 45 51 56 62 73 79 84 90 0
01 07 12 18 29 35 40 46 57 63 68 74 85 91 96 1
02 13 19 24 30 41 47 52 58 69 75 80 86 97 2
03 08 14 25 31 36 42 53 59 64 70 81 87 92 98 3
09 15 20 26 37 43 48 54 65 71 76 82 93 99 4
04 10 21 27 32 38 49 55 60 66 77 83 88 94 5
05 11 16 22 33 39 44 50 61 67 72 78 89 95 6

This table can also be described by the following equation:

y = \left(\left\lfloor\frac{s}{4}\right\rfloor + s\right) \bmod 7

Where

s is the last two digits of the year (i.e. if the year is 1987, s = 87)
y is ...

So, for example, if you want to find 'y' for the year 1987:

\begin{align}
y &= \left(\left\lfloor\frac{87}{4}\right\rfloor + 87\right) \bmod 7 \\
  &= (21 + 87) \bmod 7 \\
  &= 108 \bmod 7 \\
  &= 3 \\
\end{align}

Schwerdtfeger's method

In a tabular method by Schwerdtfeger, the year is split into the century and the two digit year within the century. The approach depends on the month. For m ≥ 3,

 c = \left\lfloor\frac{y}{100}\right\rfloor \quad \text{and} \quad g = y - 100 c,

so g is between 0 and 99. For m = 1,2,

 c = \left\lfloor\frac{y-1}{100}\right\rfloor \quad \text{and} \quad g = y - 1 - 100 c.

The formula for the day of the week is[6]

 w = d + e + f + g + \left\lfloor\frac{g}{4}\right\rfloor \bmod 7,

where the positive modulus is chosen.[6]

The value of e is obtained from the following table:

m 1 2 3 4 5 6 7 8 9 10 11 12
e 0 3 2 5 0 3 5 1 4 6 2 4

The value of f is obtained from the following table, which depends on the calendar. For the Gregorian calendar,[6]

c mod 4 0 1 2 3
f 0 5 3 1

For the Julian calendar,[6]

c mod 7 0 1 2 3 4 5 6
f 5 4 3 2 1 0 6

Other purely mathematical algorithms

Zeller’s algorithm

<templatestyles src="Module:Hatnote/styles.css"></templatestyles>

In Zeller’s algorithm, the months are numbered from 3 for March to 14 for February. The year is assumed to begin in March; this means, for example, that January 1995 is to be treated as month 13 of 1994.[8] The formula for the Gregorian calendar is

 w = \left(d + \left\lfloor\frac{13(m+1)}{5}\right\rfloor + y + \left\lfloor\frac{y}{4}\right\rfloor + \left\lfloor\frac{c}{4}\right\rfloor - 2c\right) \bmod 7,

where

  • Y is the year minus 1 for January or February, and the year for any other month
  • y is the last 2 digits of Y
  • c is the first 2 digits of Y
  • d is the day of the month (1 to 31)
  • m is the shifted month (March=3,...February=14)
  • w is the day of week (1=Sunday,..0=Saturday)

The only difference is one between Zeller’s algorithm (Z) and the Gaussian algorithm (G), that is ZG = 1 = Sunday.

 (d + \lfloor(m + 1)2.6\rfloor + y +\lfloor y/4\rfloor + \lfloor c/4\rfloor - 2c) \bmod 7 - (d + \lfloor 2.6m - 0.2\rfloor + y +\lfloor y/4\rfloor + \lfloor c/4\rfloor - 2c) \bmod 7
 = (\lfloor(m + 2 + 1)2.6 - (2.6m - 0.2)\rfloor) \bmod 7 (March = 3 in Z but March = 1 in G)
 = (\lfloor 2.6m + 7.8 - 2.6m + 0.2\rfloor) \bmod 7
 = 8 \bmod 7 = 1

So we can get the values of months from those for the Gaussian algorithm by adding one:

Months                m
January               1
February              4 
March                 3
April                 6
May                   1
June                  4
July                  6
August                2
September             5
October               0
November              3
December              5

Lewis Carroll's method

Charles Lutwidge Dodgson (Lewis Carroll) devised a method resembling a puzzle, yet partly tabular in using identical values to those in the Months table given above: he lists the same three adjustments for the first three months of non-leap years, one 7 higher for the last, and gives cryptic instructions for finding the rest; his adjustments for centuries are to be determined using formulas identical to those for the Centuries table. As will be seen, his method works for both old style (Julian) and new style dates, the year in each case assumed to begin on 1 January.[9]

Algorithm: Take the given date in 4 portions, viz. the number of centuries, the number of years over, the month, the day of the month. Compute the following 4 items, adding each, when found, to the total of the previous items. When an item or total exceeds 7, divide by 7, and keep the remainder only.

The Century-item For Old Style (which ended September 2, 1752) subtract from 18. For New Style (which began September 14) divide by 4, take overplus from 3, multiply remainder by 2.

The Year-item Add together the number of dozens, the overplus, and the number of 4s in the overplus.

The Month-item If it begins or ends with a vowel, subtract the number, denoting its place in the year, from 10. This, plus its number of days, gives the item for the following month. The item for January is "0"; for February or March, "3"; for December, "12".

The Day-item The total, thus reached, must be corrected, by deducting "1" (first adding 7, if the total be "0"), if the date be January or February in a leap year: remembering that every year, divisible by 4, is a Leap Year, excepting only the century-years, in New Style, when the number of centuries is not so divisible (e.g. 1800).

The final result gives the day of the week, "0" meaning Sunday, "1" Monday, and so on.

Examples:

1783, September 18

17, divided by 4, leaves "1" over; 1 from 3 gives "2"; twice 2 is "4". 83 is 6 dozen and 11, giving 17; plus 2 gives 19, i.e. (dividing by 7) "5". Total 9, i.e. "2" The item for August is "8 from 10", i.e. "2"; so, for September, it is "2 plus 31", i.e. "5" Total 7, i.e. "0", which goes out. 18 gives "4". Answer, "Thursday".

1676, February 23

16 from 18 gives "2" 76 is 6 dozen and 4, giving 10; plus 1 gives 11, i.e. "4". Total "6" The item for February is "3". Total 9, i.e. "2" 23 gives "2". Total "4" Correction for Leap Year gives "3". Answer, "Wednesday"[10]

Implementation-dependent methods

In the C language expressions below, y, m and d are, respectively, integer variables representing the year (e.g., 1988), month (1-12) and day of the month (1-31).

        (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7

In 1990, Michael Keith and Tom Craver published the foregoing expression that seeks to minimise the number of keystrokes needed to enter a self-contained function for converting a Gregorian date into a numerical day of the week.[11] It preserves neither y nor d, and returns 0 = Sunday, 1 = Monday, etc.

Shortly afterwards, Hans Lachman streamlined their algorithm for ease of use on low-end devices. As designed originally for four-function calculators, his method needs fewer keypad entries by limiting its range either to A.D. 1905-2099, or to historical Julian dates. It was later modified to convert any Gregorian date, even on an abacus. On Motorola 68000-based devices, there is similarly less need of either processor registers or opcodes, depending on the intended design objective.[12]

The tabular forerunner to Tøndering's algorithm is embodied in the following K&R C function.[13] With minor changes, it is adaptable to other high level programming languages such as APL2.[14] (A 6502 assembly language version exists as well).  Posted by Tomohiko Sakamoto on the comp.lang.c Usenet newsgroup in 1993, it is accurate for any Gregorian date:

    dayofweek(y, m, d)	/* 1 <= m <= 12,  y > 1752 (in the U.K.) */
    {
        static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
        y -= m < 3;
        return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
    }

The function does not always preserve y, and returns 0 = Sunday, 1 = Monday, etc. In contrast, the following expression

    dow(m,d,y){y-=m<3;return(y+y/4-y/100+y/400+"-bed=pen+mad."[m]+d)%7;}

posted simultaneously by Sakamoto is not only not easily adaptable to other languages, but may even fail if compiled on a computer that encodes characters using other than standard ASCII values (e.g. EBCDIC), or on C compilers that enforce ANSI C compliance (even on code that is still compliant with the original K&R C specification, where omitted type declarations are assumed to be integer). For the latter consideration alone, Sakamoto's more-verbose version might be considered non-portable, as might also that of Keith and Craver.

Rata Die

<templatestyles src="Module:Hatnote/styles.css"></templatestyles>

IBM's Rata Die method requires that one knows the day of the week of the first calendar date on the proleptic Gregorian calendar: January 1, AD 1. This has to be done to establish the remainder number based on which the day of the week is determined for the latter part of the analysis. By using a given day August 13, 2009 which was a Thursday as a reference, with Base and n being the number of days and weeks it has been since 01/01/0001 to the given day, respectively and k the day into the given week which must be less than 7, Base is expressed as

       Base = 7n + k                                                                                  (i)

Knowing that a year divisible by 4 or 400 is a leap year while a year divisible by 100 and not 400 is not a leap year, a software program can be written to find the number of days. The following is a translation into C of IBM's method for its REXX programming language. The function does not preserve d, except for dates in January.

static char daytab[2][13] =
{
		{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
		{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
for (year = 1; year <= y; year++)
{
	leap  = year%4 == 0;
	if (year%100 == 0 && year%400 != 0)
		leap = 0;
	for (month = 1; month <= m; month++)
	{
		d += daytab[leap][month - 1];
		daystotal = 365*(year - 1) + (int)floor((year-1)/4)
		- (int)floor((year - 1)/100) + (int)floor((year - 1)/400) + d;
	}
}

It is found that daystotal is 733632 from the base date January 1, AD 1. This total number of days can be verified with a simple calculation: There are already 2008 full years since 01/01/0001. The total number of days in 2008 years not counting the leap days is 365×2008 = 732920 days. Assume that all years divisible by 4 are leap years. Add 2008/4 = 502 to the total; then subtract the 15 leap days because the years which are exactly divisible by 100 but not 400 are not leap. Continue by adding to the new total the number of days in the first seven months of 2009 that have already passed which are 31 + 28 + 31 + 30 + 31 + 30 + 31 = 212 days and the 13 days of August to get Base = 732920 + 502 – 20 + 5 + 212 + 13 = 733632.

What this means is that it has been 733632 days since the base date. Substitute the value of Base into the above equation (i) to get 733632 = 7×104804 + 4, n = 104804 and k = 4 which implies that August 13, 2009 is the fourth day into the 104805th week since 01/01/0001. 13 August 2009 is Thursday; therefore, the first day of the week must be Monday, and it is concluded that the first day 01/01/0001 of the calendar is Monday. Based on this, the remainder of the ratio Base/7, defined above as k, decides what day of the week it is. If k = 0, it’s Monday, k = 1, it’s Tuesday, etc.[15]

See also

References

  1. 1.0 1.1 Lua error in package.lua at line 80: module 'strict' not found.
  2. Lua error in package.lua at line 80: module 'strict' not found.
  3. Lua error in package.lua at line 80: module 'strict' not found. NWDOSTIP.TXT is a comprehensive work on Novell DOS 7 and OpenDOS 7.01, including the description of many undocumented features and internals. It is part of the author's yet larger MPDOSTIP.ZIP collection maintained up to 2001 and distributed on many sites at the time. The provided link points to a HTML-converted older version of the NWDOSTIP.TXT file.
  4. Richards, E.G. (1999). Mapping Time: The Calendar and Its History. Oxford University Press.
  5. 5.0 5.1 Lua error in package.lua at line 80: module 'strict' not found.
  6. 6.0 6.1 6.2 6.3 6.4 6.5 6.6 Lua error in package.lua at line 80: module 'strict' not found.
  7. 7.0 7.1 Lua error in package.lua at line 80: module 'strict' not found.
  8. Lua error in package.lua at line 80: module 'strict' not found.
  9. Lewis Carroll, "To Find the Day of the Week for Any Given Date", Nature, March 31, 1887.
  10. Martin Gardner, "The Universe in a Handkerchief: Lewis Carroll's Mathematical Recreations, Games, Puzzles, and Word Plays", pages 24-26, Springer-Verlag, 1996
  11. Michael Keith and Tom Craver. (1990). The ultimate perpetual calendar? Journal of Recreational Mathematics, 22:4, pp.280-282.
  12. The 4-function Calculator; The Assembly of Motorola 68000 Orphans; The Abacus. gopher://sdf.org/1/users/retroburrowers/TemporalRetrology
  13. "Day-of-week algorithm NEEDED!" news:1993Apr20.075917.16920@sm.sony.co.jp
  14. APL2 IDIOMS workspace: Date and Time Algorithms, line 15. ftp://ftp.software.ibm.com/ps/products/apl2/info/APL2IDIOMS.pdf (2002)
  15. REXX/400 Reference manual page 87 (1997).
  • Lua error in package.lua at line 80: module 'strict' not found.
  • Lua error in package.lua at line 80: module 'strict' not found.
  • Lua error in package.lua at line 80: module 'strict' not found.
  • Lua error in package.lua at line 80: module 'strict' not found.

External links