Jump to content

Determination of the day of the week: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Undid revision 527343963 by 117.27.153.199 (talk)
Undid revision 527284548 by Materialscientist (talk) restore material relating to Dodgson's mistake
Line 57: Line 57:
The system of [[dominical letter]]s assigns a letter from A through G to each day of the year. In a leap year, February 29, the [[Bissextile#Leap_day|bissextile day]], does not have a distinct letter. This causes all subsequent Sundays to be associated with a different dominical letter than those in the beginning of the year, so all leap years get two dominical letters. In this system, the "dominical letter" for a year is the letter which corresponds to the Sundays of that year.
The system of [[dominical letter]]s assigns a letter from A through G to each day of the year. In a leap year, February 29, the [[Bissextile#Leap_day|bissextile day]], does not have a distinct letter. This causes all subsequent Sundays to be associated with a different dominical letter than those in the beginning of the year, so all leap years get two dominical letters. In this system, the "dominical letter" for a year is the letter which corresponds to the Sundays of that year.


==Standard tabular method==
==A tabular method to calculate the day of the week==


This fairly simple method is valid for the [[Gregorian calendar]] only. Britain and its colonies started using the Gregorian calendar on Thursday, September 14, 1752 (the previous day was Wednesday, September 2, 1752 [[Old Style and New Style dates|(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.
This method is valid for the [[Gregorian calendar]] as well as 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 and New Style dates|(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 method requires one to know four input parameters to find four numbers to sum. Using modulus to restrict results to 0 through
The formula is <math>d + m + y + \frac{y}{4} + c \mod {7}</math>, ignoring the remainder of <math>\frac{y}{4}</math> where:
6, the day of the week can be determined. Since this method uses the "zeroeth" day, we can add the day of the month directly (without
* ''d'' is the day of the month
subtracting 1). Examples of the evaluation of this method are below. The four inputs and four resulting summands are:
* ''m'' is the month's number in the [[Determination of the day of the week#Months' table|months' table]]
* ''y'' is the last two digits of the year
* ''c'' is the century number. This is 6 if the first two digits of the year are evenly divisible by 4, and subsequent centuries are 4-2-0 (so the century numbers for 2000, 2100, 2200, and 2300 are respectively 6, 4, 2, and 0).


#''Century:'' Where <math>century</math> is the first two digits of the year, the first summand is to be taken from the centuries' table below based on the rule: <math>c = 2(3 - (century\mod {4}))</math> for Gregorian dates; <math>c = (4 - century)\mod {7}</math> for Julian dates. With Sunday being day 0, each number represents the day of the week on which March 25th ([[Lady Day]]) occurs in year 0 of the century.
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.
#''Year:'' Where <math>year</math> is the last two digits of the year, the second summand is to be taken from the years' table. Because there are 365 days in a common year, which is 52 weeks plus 1 day, each year will start on the day of the week after that starting the preceding year. A leap year is 52 weeks plus 2 days. Given the day that starts a century (from above), adding the number of years since the start of the century, to the number of leap years since the start of the century, leads one to the day of the week on which the year starts.
#''Month:'' The third summand is to be taken from the months' table below. N.B.: each month is taken to start at day "zero."
#''Day of the Month:'' Use the day number itself as the fourth summand, or use the value from the days' table below, based on the rule: <math>d = day \mod {7}</math>.
Now add the summands and look up the remainder of a division by 7 in the days' table to get the
''Day of the week:'' <math>w = (c + y + m + d)\mod 7</math>

===Examples===
For a Julian example of the tabular method, let's use October 13, 1307.

#Look up the 1300s in the centuries' table: 5
#Look up the 07 in the years' table: 1
#Look up October in the months' table: 0
#Look up the day of the month in the days' table (in this case, 13): 6
#Add all numbers from steps 1–4: 5+1+0+6=12
#Divide the sum from step 5 by 7 and find the remainder: 12/7=1 remainder 5
#Look up the remainder in the days' table: 5=Friday.

Let's try January 30, 1648 Old Style (commemorating separation of church & head of state)

#Look up the 1600s in the centuries' table: 2
#Look up the 48 in the years' table: 4
#Look up (January) in the months' table: 1
#Look up the day of the month in the days' table (in this case, 30): 2
#Add all numbers from steps 1–4: 2+4+1+2=9
#Divide the sum from step 5 by 7 and find the remainder: 9/7=1 remainder 2
#Look up the remainder in the days' table: 2=Tuesday.

Now let's try April 24, 1982.

#Look up the 1900s in the centuries' table: 0
#Look up the 82 in the years' table: 4
#Look up April in the months' table: 6
#Look up the day of the month in the days' table (in this case, 24): 3
#Add all numbers from steps 1–4: 0+4+6+3=13
#Divide the sum from step 5 by 7 and find the remainder: 13/7=1 remainder 6
#Look up the remainder in the days' table: 6=Saturday.

Let's try non-leap 00 year March 25, 1900

#Look up the 1900s in the centuries' table: 0
#Look up the 00 in the years' table: 0
#Look up March in the months' table: 3
#Look up the day of the month in the days' table (in this case, 25): 4
#Add all numbers from steps 1–4: 0+0+3+4=7.
#Divide the sum from step 5 by 7 and find the remainder: 7/7=1 remainder 0
#Look up the remainder in the days' table: 0=Sunday.

Let's try [[leap year]] January 1, 2000

#Look up the 2000s in the centuries' table: 6
#Look up the ''00'' in the years' table: 6
#Look up January in the months' table: 0
#Use the day of the month (in this case, 1): 1
#Add all numbers from steps 1–4: 6+6+0+1=13.
#Divide the sum from step 5 by 7 and find the remainder: 13/7=1 remainder 6
#Look up the remainder in the days' table: 6=Saturday.

Finally, let's try June 19, 2054

#Look up the 2000s in the centuries' table: 6
#Look up the 54 in the years' table: 4
#Look up June in the months' table: 4
#Look up the day of the month in the days' table (in this case, 19): 5
#Add all numbers from steps 1–4: 6+4+4+5=19
#Divide the sum from step 5 by 7 and find the remainder: 19/7=2 remainder 5
#Look up the remainder in the days' table: 5=Friday.

===Centuries' table===
O.S. &
<u>Julian</u>___________<u>Gregorian</u>
1 1000-1099
0 1100-1199
6 1200-1299
5 1300-1399
4 1400-1499
3 1500-1599 0 Gregorian from October 15, 1582
2 1600-1699 6
1 1700-1799 4 (Still the Old-Style Calendar in British territories until 1752)
0 1800-1899 2
6 1900-1999 0
5 2000-2099 6
4 2100-2199 4
3 2200-2299 2
2 2300-2399 0
1 2400-2499 6
0 2500-2599 4
6 2600-2699 2

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


===Months' table===
===Months' table===
January 0
February 3
March 3 (as of the 25th for [[Old Style]] dates)
April 6
May 1
June 4
July 6
August 2
September 5
October 0
November 3
December 5
(January 1 for [[Old Style]] dates)
(February 4 for [[Old Style]] dates)
(March 4 prior to the 25th for O.S. dates in non-leap years)
(''March'' 5 prior to the 25th for O.S. dates in leap years)


===Days' table===
{| class="wikitable sortable"
01 08 15 22 29 1 Monday
|-
02 09 16 23 30 2 Tuesday
! class="unsortable"|Month !! Number
03 10 17 24 31 3 Wednesday
|-
04 11 18 25 4 Thursday
| January || 1
05 12 19 26 5 Friday
|-
06 13 20 27 6 Saturday
| February || 4
07 14 21 28 0 Sunday
|-
| March || 4
|-
| April || 0
|-
| May || 2
|-
| June || 5
|-
| July || 0
|-
| August || 3
|-
| September || 6
|-
| October || 1
|-
| November || 4
|-
| December || 6
|}


==Other methods==
==Purely mathematical methods==


===Gaussian algorithm===
===Gaussian algorithm===
The Gaussian algorithm is even more compact, working without a months table. A slight disadvantage is the unusual month and year counting convention. The formula is
The Gaussian algorithm is much more compact and works without any lookup tables. A slight disadvantage is the unusual month and year counting convention. The formula is


<math>w = (d + \lfloor 2.6 \cdot m - 0.2 \rfloor + y + \left\lfloor\frac{y}{4}\right\rfloor + \left\lfloor\frac{c}{4}\right\rfloor - 2c)\ \bmod\ 7</math>
<math>w = (d + \lfloor 2.6 \cdot m - 0.2 \rfloor + y + \left\lfloor\frac{y}{4}\right\rfloor + \left\lfloor\frac{c}{4}\right\rfloor - 2c)\ \bmod\ 7</math>
Line 117: Line 213:


Note: There are two different ways that [[Modulo operation|modulo]] can handle negative numbers. For this equation to work properly '<math>(...)\ \bmod\ 7</math>' needs to return a positive number if '<math>(...)</math>' is a negative number.
Note: There are two different ways that [[Modulo operation|modulo]] can handle negative numbers. For this equation to work properly '<math>(...)\ \bmod\ 7</math>' needs to return a positive number if '<math>(...)</math>' is a negative number.
In case of January and February gives incorrect values. Hence use the corresponding same months "m" value for these two months depending on whether it is leap year or not. e.g. leap year for February use m=6 and January m = 2; similarly, for non leap years use Feb m = 1 and Jan m = 8.
In case of January and February gives incorrect values. Hence use the corresponding same months "m" value for these two months depending on whether it is leap year or not. e.g. leap year for February use m=6 and January m = 2,similarly for non leap year in feb m = 1 and jan m = 8.


===Zeller’s algorithm===
===Zeller’s algorithm===
Line 153: Line 249:
gopherite.org/0/users/lachman/TemporalRetrology/68k/g68</ref>
gopherite.org/0/users/lachman/TemporalRetrology/68k/g68</ref>


The tabular forerunner to Tondering's algorithm is embodied in the following [[ANSI C]] function. With minor changes, it is adaptable to other
The tabular forerunner to Tøndering's algorithm is embodied in the following [[ANSI C]] function. With minor changes, it is adaptable to other
[[high level programming language]]s such as [[APL2]].<ref>ftp.software.ibm.com/ps/products/apl2/info/APL2IDIOMS.pdf p.9.</ref>
[[high level programming language]]s such as [[APL2]].<ref>ftp.software.ibm.com/ps/products/apl2/info/APL2IDIOMS.pdf p.9.</ref>
(A [[6502]] [[assembly language]] version exists as well.)&nbsp; Devised by Tomohiko Sakamoto in
(A [[6502]] [[assembly language]] version exists as well.)&nbsp; Devised by Tomohiko Sakamoto in

Revision as of 21:27, 11 December 2012

There are various methods to calculate the day of the week for any particular date in the past or future.

A typical application is to calculate the day of the week on which someone was born or some other special event occurred.

Introduction

To determine the day of the week from numerical operations, it is necessary to represent Sunday to Saturday as numbers (usually from 0 to 6, 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 we can treat 7 as 0, 8 as 1, 9 as 2, 18 as 4 and so on; the interpretation of this being that if we signify Sunday as day 0, then 7 days later (i.e. day 7) is also a Sunday, and day 18 will be the same as day 4, which is a Thursday since this falls 4 days after Sunday.

The basic approach of nearly all of the methods to calculate the day of the week begins by starting from 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 on which one applies modulo 7 to determine the day of the week of the date.

Some methods do all the additions first and then cast out sevens, whereas others cast them out at each step, as in Charles Lutwidge Dodgson's method.[1] 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 September 1 falls on the same day as December 1. 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 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 February 29 means each subsequent month starts a day later.

Here is how the months correspond: For common years:

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

For leap year:

  • 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. For example, 2011 is a common year starting on Saturday, meaning that 2011 corresponds to the 2005 calendar year. 2012, on the other hand, is a leap year starting on Sunday, meaning that the first two months of the year begin on the same day as they do in 2006 (i.e. January 1 is a Sunday and February 1 is a Wednesday) but because of leap day the last ten months correspond to the last ten months in 2007 (i.e. March 1 is a Thursday, etc.).

Dominical letters

The system of dominical letters assigns a letter from A through G to each day of the year. In a leap year, February 29, the bissextile day, does not have a distinct letter. This causes all subsequent Sundays to be associated with a different dominical letter than those in the beginning of the year, so all leap years get two dominical letters. In this system, the "dominical letter" for a year is the letter which corresponds to the Sundays of that year.

A tabular method to calculate the day of the week

This method is valid for the Gregorian calendar as well as 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 method requires one to know four input parameters to find four numbers to sum. Using modulus to restrict results to 0 through 6, the day of the week can be determined. Since this method uses the "zeroeth" day, we can add the day of the month directly (without subtracting 1). Examples of the evaluation of this method are below. The four inputs and four resulting summands are:

  1. Century: Where is the first two digits of the year, the first summand is to be taken from the centuries' table below based on the rule: for Gregorian dates; for Julian dates. With Sunday being day 0, each number represents the day of the week on which March 25th (Lady Day) occurs in year 0 of the century.
  2. Year: Where is the last two digits of the year, the second summand is to be taken from the years' table. Because there are 365 days in a common year, which is 52 weeks plus 1 day, each year will start on the day of the week after that starting the preceding year. A leap year is 52 weeks plus 2 days. Given the day that starts a century (from above), adding the number of years since the start of the century, to the number of leap years since the start of the century, leads one to the day of the week on which the year starts.
  3. Month: The third summand is to be taken from the months' table below. N.B.: each month is taken to start at day "zero."
  4. Day of the Month: Use the day number itself as the fourth summand, or use the value from the days' table below, based on the rule: .

Now add the summands and look up the remainder of a division by 7 in the days' table to get the Day of the week:

Examples

For a Julian example of the tabular method, let's use October 13, 1307.

  1. Look up the 1300s in the centuries' table: 5
  2. Look up the 07 in the years' table: 1
  3. Look up October in the months' table: 0
  4. Look up the day of the month in the days' table (in this case, 13): 6
  5. Add all numbers from steps 1–4: 5+1+0+6=12
  6. Divide the sum from step 5 by 7 and find the remainder: 12/7=1 remainder 5
  7. Look up the remainder in the days' table: 5=Friday.

Let's try January 30, 1648 Old Style (commemorating separation of church & head of state)

  1. Look up the 1600s in the centuries' table: 2
  2. Look up the 48 in the years' table: 4
  3. Look up (January) in the months' table: 1
  4. Look up the day of the month in the days' table (in this case, 30): 2
  5. Add all numbers from steps 1–4: 2+4+1+2=9
  6. Divide the sum from step 5 by 7 and find the remainder: 9/7=1 remainder 2
  7. Look up the remainder in the days' table: 2=Tuesday.

Now let's try April 24, 1982.

  1. Look up the 1900s in the centuries' table: 0
  2. Look up the 82 in the years' table: 4
  3. Look up April in the months' table: 6
  4. Look up the day of the month in the days' table (in this case, 24): 3
  5. Add all numbers from steps 1–4: 0+4+6+3=13
  6. Divide the sum from step 5 by 7 and find the remainder: 13/7=1 remainder 6
  7. Look up the remainder in the days' table: 6=Saturday.

Let's try non-leap 00 year March 25, 1900

  1. Look up the 1900s in the centuries' table: 0
  2. Look up the 00 in the years' table: 0
  3. Look up March in the months' table: 3
  4. Look up the day of the month in the days' table (in this case, 25): 4
  5. Add all numbers from steps 1–4: 0+0+3+4=7.
  6. Divide the sum from step 5 by 7 and find the remainder: 7/7=1 remainder 0
  7. Look up the remainder in the days' table: 0=Sunday.

Let's try leap year January 1, 2000

  1. Look up the 2000s in the centuries' table: 6
  2. Look up the 00 in the years' table: 6
  3. Look up January in the months' table: 0
  4. Use the day of the month (in this case, 1): 1
  5. Add all numbers from steps 1–4: 6+6+0+1=13.
  6. Divide the sum from step 5 by 7 and find the remainder: 13/7=1 remainder 6
  7. Look up the remainder in the days' table: 6=Saturday.

Finally, let's try June 19, 2054

  1. Look up the 2000s in the centuries' table: 6
  2. Look up the 54 in the years' table: 4
  3. Look up June in the months' table: 4
  4. Look up the day of the month in the days' table (in this case, 19): 5
  5. Add all numbers from steps 1–4: 6+4+4+5=19
  6. Divide the sum from step 5 by 7 and find the remainder: 19/7=2 remainder 5
  7. Look up the remainder in the days' table: 5=Friday.

Centuries' table

O.S. &
Julian___________Gregorian
  1    1000-1099
  0    1100-1199
  6    1200-1299
  5    1300-1399
  4    1400-1499     
  3    1500-1599     0     Gregorian from October 15, 1582
  2    1600-1699     6
  1    1700-1799     4    (Still the Old-Style Calendar in British territories until 1752)
  0    1800-1899     2
  6    1900-1999     0 
  5    2000-2099     6
  4    2100-2199     4
  3    2200-2299     2
  2    2300-2399     0
  1    2400-2499     6
  0    2500-2599     4
  6    2600-2699     2

Years' table

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

Italic numbers for (non-Old-Style) January & February during leap years

Months' table

 January      0 
 February     3 
 March        3  (as of the 25th for Old Style dates)
 April        6
 May          1
 June         4
 July         6
 August       2
 September    5
 October      0
 November     3
 December     5
(January      1   for Old Style dates)
(February     4   for Old Style dates)
(March        4   prior to the 25th for O.S. dates in non-leap years)
(March        5   prior to the 25th for O.S. dates in leap years)

Days' table

01 08 15 22 29    1     Monday
02 09 16 23 30    2     Tuesday
03 10 17 24 31    3     Wednesday
04 11 18 25       4     Thursday
05 12 19 26       5     Friday
06 13 20 27       6     Saturday
07 14 21 28       0     Sunday

Purely mathematical methods

Gaussian algorithm

The Gaussian algorithm is much more compact and works without any lookup tables. A slight disadvantage is the unusual month and year counting convention. The formula is

Where

     Y: year-1 for  January or February, 
        year   for  the rest of the year
     d: day (1 to 31)
     m: shifted month (March=1,...February=12), i.e. ((month + 9)% 12) + 1     
     y: last 2 digits of Y
     c: first 2 digits of Y
     w: day of week (0=Sunday,..6=Saturday)

Note: There are two different ways that modulo can handle negative numbers. For this equation to work properly '' needs to return a positive number if '' is a negative number. In case of January and February gives incorrect values. Hence use the corresponding same months "m" value for these two months depending on whether it is leap year or not. e.g. leap year for February use m=6 and January m = 2,similarly for non leap year in feb m = 1 and jan m = 8.

Zeller’s algorithm

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.

Tøndering's algorithm

Claus Tøndering's algorithm uses a variant of the method of congruence used by Gauss, thereby shifting month-numbers by the same amount, and arriving at the same adjustment for a given month. It differs from the rest of the Gaussian algorithm by not splitting off the nominal century from the year, and by dividing itself into separate equations - the last being equivalent term-for-term to the expression used in Sakamoto's method to calculate the day of the week.[2]

Other methods (using tables or computational devices)

Dodgson's method

Charles Lutwidge Dodgson devised a method resembling a puzzle, yet partly the same as the tabular method given above: he lists the same three adjustments for the first three months, 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. Although claiming to use a modification for Old Style dates, the one he uses to determine that "1676, February 23" is a Wednesday, only works on the New Style Julian calendar.

Implementation-dependent methods of Sakamoto, Lachman, Keith and Craver

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.[3] 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.[4] 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.[5] On Motorola 68000-based devices, there is similarly less need of either processor registers or opcodes.[6]

The tabular forerunner to Tøndering's algorithm is embodied in the following ANSI C function. With minor changes, it is adaptable to other high level programming languages such as APL2.[7] (A 6502 assembly language version exists as well.)  Devised by Tomohiko Sakamoto in 1993,[8] it is accurate for any Gregorian date:

   int dow(int y, int m, int d)
   {
       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.

Babwani's method

Sohael Babwani developed an alternative method that enables one not only to find the day of the week but also a date, when the day, month and year are given.[9] It uses a months' table in a manner identical to the one above, and numbers months normally from 1 for January to 12 for December.[10]

See also

References

  1. ^ Richards, E.G. (1999). Mapping Time: The Calendar and Its History. Oxford University Press.
  2. ^ www.tondering.dk/claus/cal/chrweek.php#calcdow
  3. ^ Michael Keith and Tom Craver. (1990). The ultimate perpetual calendar?, Journal of Recreational Mathematics, 22:4, pp.280-282.
  4. ^ gopherite.org/0/users/lachman/TemporalRetrology/cc/jg
  5. ^ gopherite.org/0/users/lachman/TemporalRetrology/A/G
  6. ^ gopherite.org/0/users/lachman/TemporalRetrology/68k/g68
  7. ^ ftp.software.ibm.com/ps/products/apl2/info/APL2IDIOMS.pdf p.9.
  8. ^ groups.google.com/group/comp.lang.c/msg/ce353009f08558b9?hl=en&dmode=source
  9. ^ Sohael Babwani (2004). An extended approach to the Julian and the Gregorian calendar, The Mathematical Gazette, 88:77, pp. 569–573.
  10. ^ babwani-congruence.blogspot.com/2009/08/frequently-asked-questions_11.html