Determination of The Day of The Week - Metapedia
Determination of The Day of The Week - Metapedia
From Metapedia
This article details 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.
Contents
1 Introduction 2 Useful concepts 2.1 Corresponding months 2.2 Corresponding years 2.2.1 Dominical letters 3 A tabular method to calculate the day of the week 3.1 Examples 3.2 Centuries table 3.3 Months table 3.4 Days table 4 Purely mathematical methods 4.1 Gaussian algorithm 4.2 Zellers algorithm 4.3 Tondering's algorithm 5 Other methods (using tables or computational devices) 5.1 Dodgson's method 5.2 Implementation-dependent methods of Sakamoto, Lachman, Keith and Craver 5.3 Babwani's method 6 See also 7 References 8 External links 9 Internal Links
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 days 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 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's how the months correspond: Common year January and October. February, March and November. April and July. No month corresponds to August. Leap year January, April and July. February and August. March and November. No month corresponds to October. All Years September and December. No month corresponds to May or June.
Note that 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 as they do 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 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.
January and February in leap years; other methods, such as Charles Dodgson's, leave the adjustment until the end by, in his own words, "deducting '1' (first adding 7, if the total be '0'), if the date be January or February of a leap year." 4. Day of the Month: Once we know on which day of the week the month starts, we simply add the day of the month to find the final result (noting that as mentioned above, we've been working with the "zeroeth" day of the month as the start).
Examples
Now for an example of the complete method, let's use April 24, 1982. 1. 2. 3. 4. 5. 6. 7. Look up the 1900s in the centuries table: 0 Note the last two digits of the year: 82 Divide the 82 by 4: 82/4 = 20.5 and drop the fractional part: 20 Look up April in the months table: 6 Add all numbers from steps 14 to the day of the month (in this case, 24): 0+82+20+6+24=132. Divide the sum from step 5 by 7 and find the remainder: 132/7=18 remainder 6 Find the remainder in the days table: 6=Saturday.
Now let's try September 18, 1783. 1. 2. 3. 4. 5. 6. 7. Look up the 1700s in the centuries table: 4 Note the last two digits of the year: 83 Divide the 83 by 4: 83/4 = 20.75 and drop the fractional part: 20 Look up September in the months table: 5 Add all numbers from steps 14 to the day of the month (in this case, 18): 4+83+20+5+18=130. Divide the sum from step 5 by 7 and find the remainder: 130/7=18 remainder 4 Find the remainder in the days table: 4=Thursday.
Let's try leap year January 1, 2000 1. 2. 3. 4. 5. 6. 7. Look up the 2000s in the centuries table: 6 Note the last two digits of the year: 00 Divide the 00 by 4: 0/4 = 0 and drop the fractional part: 0 Look up January in the months table: 6 (leap) Add all numbers from steps 14 to the day of the month (in this case, 1): 6+00+0+6+1=13. Divide the sum from step 5 by 7 and find the remainder: 13/7=1 remainder 6 Find the remainder in the days table: 6=Saturday.
Finally, let's try June 19, 2054 1. 2. 3. 4. 5. 6. Look up the 2000s in the centuries table: 6 Note the last two digits of the year: 54 Divide the 54 by 4: 54/4 = 13.5 and drop the fractional part: 13 Look up June in the months table: 4 Add all numbers from steps 14 to the day of the month (in this case, 19): 6+54+13+4+19=96. Divide the sum from step 5 by 7 and find the remainder: 96/7=13 remainder 5
Centuries table
1 7 0 0 1 7 9 9 1 8 0 0 1 8 9 9 1 9 0 0 1 9 9 9 2 0 0 0 2 0 9 9 2 1 0 0 2 1 9 9 2 2 0 0 2 2 9 9 2 3 0 0 2 3 9 9 2 4 0 0 2 4 9 9 2 5 0 0 2 5 9 9 2 6 0 0 2 6 9 9 4 2 0 6 4 2 0 6 4 2 ( S t i l lt h eO l d S t y l eC a l e n d a ri nB r i t i s hT e r r i t o r i e su n t i l1 7 5 2 )
Months table
J a n u a r y F e b r u a r y M a r c h A p r i l M a y J u n e J u l y A u g u s t S e p t e m b e r O c t o b e r N o v e m b e r D e c e m b e r 0( i nl e a py e a r6 ) 3( i nl e a py e a r2 ) 3 6 1 4 6 2 5 0 3 5
Days table
S u n d a y 0 M o n d a y 1 T u e s d a y 2 W e d n e s d a y3 T h u r s d a y 4 F r i d a y 5 S a t u r d a y 6
One can add constants (modulo 7) to these three tables provided the constant you add to the day table is equal to the sum of the constants you add to the centuries table and the months table modulo 7.
Note: There are two different ways that 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.
Zellers algorithm
Main article: Zeller's congruence In Zellers 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.
Tondering's algorithm
Claus Tondering's algorithm uses a variant of the method of congruence used by Gauss, thereby shifting monthnumbers 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]
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 ynor 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 Tondering's algorithm is embodied in the following ANSI C function. It is adaptable with minor changes 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:
i n td o w ( i n ty ,i n tm ,i n td ) { s t a t i ci n tt [ ]={ 0 ,3 ,2 ,5 ,0 ,3 ,5 ,1 ,4 ,6 ,2 ,4 } ; y=m<3 ; r e t u r n( y+y / 4-y / 1 0 0+y / 4 0 0+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
ISO 8601 Doomsday rule Perpetual calendar Julian day#Calculation Perpetual Calendar of 800 Years
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. 569573. 10. babwani-congruence.blogspot.com/2009/08/frequently-asked-questions_11.html
External links
Encyclopedia of mental calculation of the day of the week by Hans-Christian Solka, 2010 (http://www.lybrary.com/kalender-kopf-gral-p-35993.html) Compact tabular method for memorization, also for the Julian calendar (http://katzentier.de/_misc/perpetual_calendar.htm)
(http://katzentier.de/_misc/perpetual_calendar.htm) An algorithm for both Gregorian and Julian calendars (http://www.tondering.dk/claus/cal/chrweek.php#calcdow) When countries changed from the Julian calendar (http://www.tondering.dk/claus/cal/gregorian.php#country) World records for mentally calculating the day of the week in the Gregorian calendar (http://www.recordholders.org/en/records/dates.html)
Internal Links
Time measurement and standards
[show]
Retrieved from "http://en.metapedia.org/wiki/Determination_of_the_day_of_the_week" Categories: Days of the week | Gregorian calendar | Julian calendar | Calendar algorithms This page was last modified on 10 March 2012, at 14:49. Content is available under GNU Free Documentation License 1.3.