Pages

Aug 3, 2012

Determination of the Day of the Week Part. One

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. 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 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 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 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:

Century: First, we can either refer to the centuries table below or use the rule: Where century is the first two digits of the year, define c = 2(3 - (century\mod {4})) for the Gregorian calendar and c = (4 - century)\mod 7 for the Julian calendar. With Sunday being day 0, these numbers are the day of the week that January 0 (December 31 of the previous year), fell on year 0 of the century, with one added to the value for the Julian calendar and for the Gregorian calendar when century mod 4 is 0.
Year: 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. Each leap year has of course one more day than a common year. Assuming we know on which day a century starts (from above), if we add the number of years elapsed since the start of the century, plus the number of leap years that have elapsed since the start of the century, we get the day of the week on which the year starts. Where year is the last two digits of the year, define y = year + \left\lfloor {year \over 4} \right\rfloor
Month: We can either refer to the months table below to work out on which day of the week a month starts or use the rule: Where month is 1 (January) through 12 (December), define m = \left\lfloor 3.4 + (month - 3)\mod 12\cdot 2.6 \right\rfloor \mod 7 . Notice that m - 1 for January and February.
Day of the Month: We can either refer to the days table below or use the rule: d = day\mod 7.
Day of the week: w = (c + y + m + d)\mod 7.

Examples

Now for an example of the complete method, let's use October 1, 1582.

Look up the 1500s in the centuries table: 3
Look up the 26 (82 mod28=82-56=26) in the years table: 4
Look up October in the months table: 0
Look up the day of the month (in this case, 1): 1
Add all numbers from steps 1–4: 3+4+0+1=8
Divide the sum from step 5 by 7 and find the remainder: 8/7=1 remainder 1
Find the remainder in the days table: 1=Monday.


Now let's try April 24, 1982.

Look up the 1900s in the centuries table: 0
Look up the 26 (82-56=26) in the years table: 4
Look up April in the months table: 6
Look up the day of the month (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
Find the remainder in the days table: 6=Saturday.


Let's try September 18, 1783.

Look up the 1700s in the centuries table: 4
Look up the 27 (83-56=27) in the years table: 5
Look up September in the months table: 5
Look up the day of the month (in this case, 18): 4
Add all numbers from steps 1–4 to the day of the month (in this case, 18): 4+5+5+4=18
Divide the sum from step 5 by 7 and find the remainder: 18/7=2 remainder 4
Find the remainder in the days table: 4=Thursday.


Read More Here

No comments:

Post a Comment