Determination of the day of the week
   HOME

TheInfoList



OR:

The determination of the day of the week for any date may be performed with a variety of
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing ...
s. In addition,
perpetual calendars A perpetual calendar is a calendar valid for many years, usually designed to look up the day of the week for a given date in the past or future. For the Gregorian and Julian calendars, a perpetual calendar typically consists of one of three ...
require no calculation by the user, and are essentially lookup tables. A typical application is to calculate the
day of the week In many languages, the names given to the seven days of the week are derived from the names of the classical planets in Hellenistic astronomy, which were in turn named after contemporary deities, a system introduced by the Sumerians and lat ...
on which someone was born or a specific event occurred.


Concepts

In numerical calculation, the days of the week are represented as weekday numbers. If Monday is the first day of the week, the days may be coded 1 to 7, for Monday through Sunday, as is practiced in
ISO 8601 ISO 8601 is an international standard covering the worldwide exchange and communication of date and time-related data. It is maintained by the Geneva-based International Organization for Standardization (ISO) and was first published in 1988, w ...
. The day designated with 7 may also be counted as ''0'', by applying the arithmetic modulo 7, which calculates the remainder of a number after division by 7. Thus, the number 7 is treated as 0, 8 as 1, 9 as 2, 18 as 4 and so on. If Sunday is counted as day 1, then 7 days later (i.e. day 8) is also a Sunday, and day 18 is the same as day 4, which is a Wednesday since this falls three days after Sunday. 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 1 January 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. 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 unreasonable dates will produce erroneous results.


Corresponding days

Every seventh day in a month has the same name as the previous:


Corresponding months

"Corresponding months" are those months within the calendar year that start on the same day of the week. For example, September and December correspond, because 1 September falls on the same day as 1 December (as there are precisely thirteen 7-day weeks between the two dates). 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
common year A common year is a calendar year with 365 days, as distinguished from a leap year, which has 366. More generally, a common year is one without intercalation. The Gregorian calendar (like the earlier Julian calendar) employs both common years ...
corresponds to March because February has 28 days, a number divisible by 7, 28 days being exactly four weeks. In a
leap year A leap year (also known as an intercalary year or bissextile year) is a calendar year that contains an additional day (or, in the case of a lunisolar calendar, a month) added to keep the calendar year synchronized with the astronomical year or ...
, January and February correspond to different months than in a common year, since adding 29 February means each subsequent month starts a day later. January corresponds to October in common years and April and July in leap years. February corresponds to March and November in common years and August in leap years. March always corresponds to November, April always corresponds to July, and September always corresponds to December. August does not correspond to any other month in a common year. October doesn't correspond to any other month in a leap year. May and June never correspond to any other month. 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 29 February. This means that there are 14 configurations that a year can have. All the configurations can be referenced by a
dominical letter Dominical letters or Sunday letters are a method used to determine the day of the week for particular dates. When using this method, each year is assigned a letter (or pair of letters for leap years) depending on which day of the week the year sta ...
, 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. 2021 is a common year starting on Friday, which means that it corresponds to the 2010 calendar year. The first two months of 2021 correspond to the first two months of 2016. 2022 is a common year starting on Saturday, which means that it corresponds to the 2011 calendar year. The last ten months of 2022 correspond to the last ten months of 2016. 2023 is a common year starting on Sunday, which means that it corresponds to the 2017 calendar year. 2024 is a leap year starting on Monday, which means that it corresponds to the 1996 calendar year. The first two months of 2024 correspond to the first two months of 2018. The last ten months of 2024 correspond to the last ten months of 2019. Each leap year repeats once every 28 years, and every common year repeats once every 6 years and twice every 11 years. For instance, the last occurrence of a leap year starting on Wednesday was 2020 and the next occurrence will be 2048. Likewise, the next common years starting on Friday will be 2027, 2038, and then 2049. Both of these statements are true unless a leap year is skipped, but that will not happen until 2100. For details see the table below. Notes: * Black means all the months of Common Year * Red means the first 2 months of Leap Year * Blue means the last 10 months of Leap Year


Corresponding centuries

"Year 000" is, in normal chronology, the year 1 BC (which precedes AD 1). In
astronomical year numbering Astronomical year numbering is based on AD/ CE year numbering, but follows normal decimal integer numbering more strictly. Thus, it has a year 0; the years before that are designated with negative numbers and the years after that are designated ...
the year 0 comes between 1 BC and AD 1. In the
proleptic Julian calendar The proleptic Julian calendar is produced by extending the Julian calendar backwards to dates preceding AD 8 when the quadrennial leap year stabilized. The leap years that were actually observed between the implementation of the Julian calendar in ...
, (that is, the Julian calendar as it would have been if it had been operated correctly from the start), 1 BC starts on Thursday. In the
proleptic Gregorian calendar The proleptic Gregorian calendar is produced by extending the Gregorian calendar backward to the dates preceding its official introduction in 1582. In nations that adopted the Gregorian calendar after its official and first introduction, dates occ ...
, (so called because it wasn't devised until 1582), 1 BC starts on Saturday.


Tabular methods to calculate the day of the week


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 "" through "" 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 ''x''00 years). 20 indicates that 2000 is a leap year. Use Jan and Feb only in leap years. 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, 19×7=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. . 73/7=10 remainder 3. Day of week = Tuesday.


Dominical Letter

To find the
Dominical Letter Dominical letters or Sunday letters are a method used to determine the day of the week for particular dates. When using this method, each year is assigned a letter (or pair of letters for leap years) depending on which day of the week the year sta ...
, calculate the day of the week for either 1 January or 1 October. If it is Sunday, the Dominical 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).


The "doomsday"

This is an artefact of recreational mathematics. See
doomsday rule The Doomsday rule, Doomsday algorithm or Doomsday method is an algorithm of determination of the day of the week for a given date. It provides a perpetual calendar because the Gregorian calendar moves in cycles of 400 years. The algorithm for ...
for an explanation.


Check the result

Use this table for finding the day of the week without any calculations. Examples: *For common method :''26 December 1893 (GD)'' December is in row F and 26 is in column E, so the letter for the date is C located in row F and column E. 93 (year mod 100) is in row D (year row) and the letter C in the year row is located in column G. 18 ( ear/100in the Gregorian century column) is in row C (century row) and the letter in the century row and column G is B, so the day of the week is Tuesday. :''13 October 1307 (JD)'' October 13 is a F day. The letter F in the year row (07) is located in column G. The letter in the century row (13) and column G is E, so the day of the week is Friday. :''1 January 2000 (GD)'' January 1 corresponds to G, G in the year row (00) corresponds to F in the century row (20), and F corresponds to Saturday. A pithy formula for the method: ''"Date letter (G), letter (G) is in year row (00) for the letter (F) in century row (20), and for the day, the letter (F) become weekday (Saturday)"''. The Sunday Letter method Each day of the year (other than 29 February) has a letter allocated to it in the recurring sequence ABCDEFG. The series begins with A on 1 January and continues to A again on 31 December. The Sunday letter is the one which stands against all the Sundays in the year. Since 29 February has no letter, this means that the Sunday Letter for March to December is one step back in the sequence compared to that for January and February. The letter for any date will be found where the row containing the month (in black) at the left of the "Latin square" meets the column containing the date above the "Latin square". The Sunday letter will be found where the column containing the century (below the "Latin square") meets the row containing the year's last two digits to the right of the "Latin square". For a leap year, the Sunday letter thus found is the one which applies to March to December. So, for example, to find the weekday of 16 June 2020: Column "20" meets row "20" at "D". Row "June" meets column "16" at "F". As F is two letters on from D, so the weekday is two days on from Sunday, i.e. Tuesday.


Mathematical algorithms


Rata Die

The trivial
Rata Die Rata Die (R.D.) is a system for assigning numbers to calendar days (optionally with time of day), independent of any calendar, for the purposes of calendrical calculations. It was named (after the Latin ablative feminine singular for "from a fixed ...
method works by adding up the number of days that has passed since a date of known day of the week . The day of-the-week is then given by , conforming to whatever convention was used to encode . This method is more expensive than needed, and is not practical for human calculation. IBM has used a Rata Die method in its
REXX Rexx (Restructured Extended Executor) is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. P ...
programming language, using the known base date of 1 January, AD 1, a Monday. For example, the date of 13 August 2009 is 733632 days from January AD 1. Taking the number mod 7 yields 4, hence a Thursday.


Gauss's algorithm

Carl Friedrich Gauss Johann Carl Friedrich Gauss (; german: Gauß ; la, Carolus Fridericus Gauss; 30 April 177723 February 1855) was a German mathematician and physicist who made significant contributions to many fields in mathematics and science. Sometimes refer ...
described a method for calculating the day of the week for 1 January in any given year in a handwritten note in a collection of astronomical tables. He never published it. It was finally included in his collected works in 1927. Compared to Rata Die, the result helps simplify the counting of years. Gauss' method was applicable to the Gregorian calendar. He numbered the weekdays from 0 to 6 starting with Sunday. He defined the following operation. ; Inputs : Year number , month number , day number . ; Output : Day of year. ; Procedure :# First determine the day-of-week of 1 January. :#* For a Gregorian calendar, the weekday is (1 + 5((A-1)\%4) + 4((A-1)\%100) + 6((A-1)\%400))\%7. Alternatively, set , , and the value is (1 + 5((Y-1)\%4) + 3(Y-1) + 5(C\%4))\%7. :#* For a Julian calendar, the weekday is R(6 + 5R(A-1,4) + 3(A-1),7) or R(6 + 5R(Y-1,4) + 3(Y-1) + 6C,7). :# Now determine the month-related offset by using the lookup table with . :# Return . The above procedure can be condensed into a single expression for the Gregorian case: : R(D + m + 5R(A-1,4) + 4R(A-1,100) + 6R(A-1,400),7)


Worked example

For year number 2000, , and , the weekday of 1 January is :\begin &= R(1 + 5R(1999,4) + 4R(1999,100) + 6R(1999,400),7)\\ &= R(1 + 1 + 4 + 0, 7)\\ & =6 \end :\begin &= R(1 + 5R(99,4) + 3\times 99 + 5R(19,4),7)\\ &= R(1 + 1 + 3 + 1,7)\\ &= 6 =\text. \end The weekdays for 30 April 1777 and 23 February 1855 are :\begin &= R(30 + 6 + 5R(1776,4) + 4R(1776,100) + 6R(1776,400),7)\\ &= R(2 + 6 + 0 + 3 + 6,7)\\ &=3=\text \end and : \begin &= R(6 + 23 + \left\lceil 2.6\times 12\right\rceil + 5R(1854,4) + 4R(1854,100) + 6R(1854,400),7)\\ &= R(6 + 2 + 4 + 3 + 6 + 5,7)\\ &= 5=\text. \end


Explanation and notes

The algorithm for the day-of-week of 1 Jan can be proven using modulo arithmetic. The main point is that because , each year adds 1 day to the progression. The rest is adjustment for leap year. The century-based versions have . The table of month offsets show a divergence in February due to the leap year. A common technique (later used by Zeller) is to shift the month to start with March, so that the leap day is at the tail of the counting. In addition, as later shown by Zeller, the table can be replaced with an arithmetic expression. This formula was also converted into graphical and tabular methods for calculating any day of the week by Kraitchik and Schwerdtfeger.


Disparate variation

The following formula is an example of a version without a lookup table. The year is assumed to begin in March, meaning dates in January and February should be treated as being part of the preceding year. The formula for the Gregorian calendar is : w = \left(d + \lfloor 2.6m - 0.2 \rfloor + y + \left\lfloor\frac\right\rfloor + \left\lfloor\frac\right\rfloor - 2c\right) \bmod 7, where * d is the day of the month (1 to 31) * m is the shifted month (March = 1,…,February = 12) * Y is the year unless m is 11 = January or 12 = February which are considered part of the preceding year, giving Y = \textit -1 * c is the century given by c = \lfloor Y/100 \rfloor * y is the year relative to the century, given by y = Y - 100c, or simply the last 2 digits of Y * w is the day of the week (0 = Sunday,…,6 = Saturday)


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. The formula for the Gregorian calendar is
:w\equiv\left(\left\lfloor \frac\right\rfloor+\left\lfloor \frac\right\rfloor+\left\lfloor\frac\right\rfloor+d+y-2c\right) \bmod 7 where * d is the day of the month (1 to 31) * m is the shifted month (March=3,...January = 13, February=14) * Y is the year unless m is 13 = January or 14 = February which are considered part of the preceding year giving Y = \textit -1 * c is the century given by c = \lfloor Y/100 \rfloor * y is the year relative to the century, given by y = Y - 100c, or simply the last 2 digits of Y * w is the day of week (1 = Sunday,..0 = Saturday) The only difference is one between Zeller's algorithm () and the Disparate Gaussian algorithm (), that is . : (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 but March = 1 in ) : = (\lfloor 2.6m + 7.8 - 2.6m + 0.2\rfloor) \bmod 7 : = 8 \bmod 7 = 1


Wang's algorithm

Wang's algorithm for human calculation of the Gregorian calendar is (the formula should be subtracted by 1 if m is 1 or 2 if the year is a leap year)
: w = \left(d - d_0(m) + y_0 - y_1 + \left\lfloor y_0/4-y_1/2\right\rfloor - 2\left(c\bmod 4 \right)\right) \bmod 7, where * is the last digit of the year (''units)'' * is the second last digit of the year (''tens'') * is the century, given by c = \lfloor \textit/100 \rfloor * is the day of the month (1 to 31) * is the month (January=1,…,December=12) * is the day of the week (0=Sunday,…,6=Saturday) * is the null-days function (month offset) with values listed in the following table An algorithm for the Julian calendar can be derived from the algorithm above : w = \left(d - d_0(m) + y_0 - y_1 + \left\lfloor y_0/4-y_1/2\right\rfloor - c\right) \bmod 7, where is a doomsday.


Other algorithms


Schwerdtfeger's method

In a partly 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 , : c = \left\lfloor\frac\right\rfloor \quad \text \quad g = y - 100 c, so is between 0 and 99. For , : c = \left\lfloor\frac\right\rfloor \quad \text \quad g = y - 1 - 100 c. The formula for the day of the week is : w = \left( d + e + f + g + \left\lfloor\frac\right\rfloor \right) \bmod 7, where the positive modulus is chosen. The value of is obtained from the following table: The value of is obtained from the following table, which depends on the calendar. For the Gregorian calendar, For the Julian calendar,


Lewis Carroll's method

Charles Lutwidge Dodgson (
Lewis Carroll Charles Lutwidge Dodgson (; 27 January 1832 – 14 January 1898), better known by his pen name Lewis Carroll, was an English author, poet and mathematician. His most notable works are '' Alice's Adventures in Wonderland'' (1865) and its sequ ...
) devised a method resembling a puzzle, yet partly tabular in using the same index numbers for the months as in the "Complete table: Julian and Gregorian calendars" 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 similar to those for the centuries table. Although explicit in asserting that his method also works for
Old Style Old Style (O.S.) and New Style (N.S.) indicate dating systems before and after a calendar change, respectively. Usually, this is the change from the Julian calendar to the Gregorian calendar as enacted in various European countries between 158 ...
dates, his example reproduced below to determine that "1676, February 23" is a Wednesday only works on a Julian calendar which starts the year on January 1, instead of March 25 as on the "Old Style"
Julian calendar The Julian calendar, proposed by Roman consul Julius Caesar in 46 BC, was a reform of the Roman calendar. It took effect on , by edict. It was designed with the aid of Greek mathematicians and astronomers such as Sosigenes of Alexandri ...
. Algorithm:Dodgson, C.L. (
Lewis Carroll Charles Lutwidge Dodgson (; 27 January 1832 – 14 January 1898), better known by his pen name Lewis Carroll, was an English author, poet and mathematician. His most notable works are '' Alice's Adventures in Wonderland'' (1865) and its sequ ...
). (1887). "To find the day of the week for any given date". ''Nature'', 31 March 1887. Reprinted in ''Mapping Time'', pp. 299-301.
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. Century-item: For '
Old Style Old Style (O.S.) and New Style (N.S.) indicate dating systems before and after a calendar change, respectively. Usually, this is the change from the Julian calendar to the Gregorian calendar as enacted in various European countries between 158 ...
' (which ended 2 September 1752) subtract from 18. For '
New Style Old Style (O.S.) and New Style (N.S.) indicate dating systems before and after a calendar change, respectively. Usually, this is the change from the Julian calendar to the Gregorian calendar as enacted in various European countries between 158 ...
' (which began 14 September 1752) divide by 4, take overplus urplusfrom 3, multiply remainder by 2. Year-item: Add together the number of dozens, the overplus, and the number of 4s in the overplus. 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". 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". Since 23 February 1676 (counting February as the second month) is, for Carroll, the same day as Gregorian 4 March 1676, he fails to arrive at the correct answer, namely "Friday," for an Old Style date that on the Gregorian calendar is the same day as 5 March 1677. Had he correctly assumed the year to begin on the 25th of March, his method would have accounted for differing year numbers—just like
George Washington George Washington (February 22, 1732, 1799) was an American military officer, statesman, and Founding Father who served as the first president of the United States from 1789 to 1797. Appointed by the Continental Congress as commander of ...
's birthday differs—between the two calendars. It is noteworthy that those who have republished Carroll's method have failed to point out his error, most notably
Martin Gardner Martin Gardner (October 21, 1914May 22, 2010) was an American popular mathematics and popular science writer with interests also encompassing scientific skepticism, micromagic, philosophy, religion, and literatureespecially the writings of Lew ...
. In 1752, the British Empire abandoned its use of the
Old Style Old Style (O.S.) and New Style (N.S.) indicate dating systems before and after a calendar change, respectively. Usually, this is the change from the Julian calendar to the Gregorian calendar as enacted in various European countries between 158 ...
Julian calendar The Julian calendar, proposed by Roman consul Julius Caesar in 46 BC, was a reform of the Roman calendar. It took effect on , by edict. It was designed with the aid of Greek mathematicians and astronomers such as Sosigenes of Alexandri ...
upon adopting the
Gregorian calendar The Gregorian calendar is the calendar used in most parts of the world. It was introduced in October 1582 by Pope Gregory XIII as a modification of, and replacement for, the Julian calendar. The principal change was to space leap years d ...
, which has become today's standard in most countries of the world. For more background, see
Old Style and New Style dates Old Style (O.S.) and New Style (N.S.) indicate dating systems before and after a calendar change, respectively. Usually, this is the change from the Julian calendar to the Gregorian calendar as enacted in various European countries between 158 ...
.


Methods in computer code


Keith

In the
C language C (''pronounced like the letter c'') is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities ...
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 minimize the number of keystrokes needed to enter a self-contained function for converting a Gregorian date into a numerical day of the week. It returns 0 = Sunday, 1 = Monday, etc. This expression uses a less cumbersome month component than does Zeller's algorithm. 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 The abacus (''plural'' abaci or abacuses), also called a counting frame, is a calculating tool which has been used since ancient times. It was used in the ancient Near East, Europe, China, and Russia, centuries before the adoption of the Hi ...
. On
Motorola 68000 The Motorola 68000 (sometimes shortened to Motorola 68k or m68k and usually pronounced "sixty-eight-thousand") is a 16/32-bit complex instruction set computer (CISC) microprocessor, introduced in 1979 by Motorola Semiconductor Products Secto ...
-based devices, there is similarly less need of either
processor registers A processor register is a quickly accessible location available to a computer's processor. Registers usually consist of a small amount of fast storage, although some registers have specific hardware functions, and may be read-only or write-only. ...
or opcodes, depending on the intended design objective.


Sakamoto's methods

The tabular forerunner to Tøndering's algorithm is embodied in the following
K&R C C (''pronounced like the letter c'') is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of ...
function. With minor changes, it was adapted for other
high level programming language In computer science, a high-level programming language is a programming language with strong abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ''elements'', be easier to use, ...
s such as
APL2 APL (named after the book ''A Programming Language'') is a programming language developed in the 1960s by Kenneth E. Iverson. Its central datatype is the multidimensional array. It uses a large range of special graphic symbols to represent mo ...
. Posted by Tomohiko Sakamoto on the comp.lang.c
Usenet newsgroup A Usenet newsgroup is a repository usually within the Usenet system, for messages posted from users in different locations using the Internet. They are discussion groups and are not devoted to publishing news. Newsgroups are technically distin ...
in 1992, it is accurate for any Gregorian date. dayofweek(y, m, d) /* 1 <= m <= 12, y > 1752 (in the U.K.) */ It returns 0 = Sunday, 1 = Monday, etc. Sakamoto also simultaneously posted a more obfuscated version: dow(m,d,y) This version encodes the month offsets in the string and as a result requires a computer that uses standard
ASCII ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Because ...
to run the algorithm correctly, reducing its portability. In addition, both algorithms omit type declarations, which is allowed in the original
K&R C C (''pronounced like the letter c'') is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of ...
but not allowed in
ANSI C ANSI C, ISO C, and Standard C are successive standards for the C programming language published by the American National Standards Institute (ANSI) and ISO/IEC JTC 1/SC 22/WG 14 of the International Organization for Standardization (ISO) and th ...
. (Tøndering's algorithm is, again, similar in structure to Zeller's congruence and Keith's short code, except that the month-related component is . Sakamoto's is somewhere between the Disparate Gaussian and the Schwerdtfeger's algorithm, apparently unaware of the expression form.)


Gauss' in MATLAB

% example date input y1=2022 m1=1 d1=1 month_offset= 3 3 6 1 4 6 2 5 0 3 5 % common year % offset if y1 leap year if mod(y1,4)

0 && mod(y1,100)

0 && mod(y1,400)

0 month_offset= 3 4 0 2 5 0 3 6 1 4 6 % leap year end % Gregor weekday_gregor=rem( d1+month_offset(m1) + 5*rem(y1-1,4) + 4*rem(y1-1,100) + 6*rem(y1-1,400),7) % Julian weekday_julian=rem(6+5*rem(y1-1,4) + 3*(y1-1),7)
0: Sunday 1: Monday .. 6: Saturday


See also

*
Doomsday rule The Doomsday rule, Doomsday algorithm or Doomsday method is an algorithm of determination of the day of the week for a given date. It provides a perpetual calendar because the Gregorian calendar moves in cycles of 400 years. The algorithm for ...
*
Julian day The Julian day is the continuous count of days since the beginning of the Julian period, and is used primarily by astronomers, and in software for easily calculating elapsed days between two events (e.g. food production date and sell by date). ...
* Mental Calculation World Cup (Has a calendar calculation contest) *
Perpetual calendar A perpetual calendar is a calendar valid for many years, usually designed to look up the day of the week for a given date in the past or future. For the Gregorian and Julian calendars, a perpetual calendar typically consists of one of three ...
*
Buddhist calendar The Buddhist calendar is a set of lunisolar calendars primarily used in Cambodia, Laos, Myanmar, India, Sri Lanka, and Thailand as well as in Malaysia, Singapore and Vietnam by Chinese populations for religious or official occasions. W ...


References


Notes


Citations


Further reading

* * *


External links


Tøndering's algorithm for both Gregorian and Julian calendars


* ttp://katzentier.de/_misc/perpetual_calendar.htm Compact tabular method for memorisation, also for the Julian calendar
When countries changed from the Julian calendar


* ttp://www.recordholders.org/en/list/mental-calculation-rankings.html National records for finding Calendar Dates
World Ranking of Memoriad Mental Calendar Dates
(all competitions combined)

{{Time measurement and standards *determination Gregorian calendar Julian calendar Calendar algorithms Articles with example C code