Determination of the day of the week


The determination of the day of the week for any date may be performed with a variety of algorithms. In addition, perpetual calendars require no calculation by the user, and are essentially lookup tables.
A typical application is to calculate the day of the week 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. 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, the number 8 as 1, the number 9 as 2, the number 18 as 4, and so on. If Sunday is counted as day 1, then 7 days later is also a Sunday, and day 18 is the same as day 4, which is a Wednesday since this falls three days after Sunday.
StandardMondayTuesdayWednesdayThursdayFridaySaturdaySundayUsage examples
ISO 86011234567 ;
0123456
2345671 ;
1234560HP 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, determining the number of days between the known day and the day to determine, and using arithmetic modulo 7 to find a new numerical day of the week.
One standard approach is to look up the value of the first day of the week of a given century, look up 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, applying modulo 7 to the day count allows determining the day of the week of that 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 can have practical use: the former is easier for calculators and computer programs, whereas the latter is easier for mental calculation. 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:
Day of
the month
00 07 14 21 280
01 08 15 22 291
02 09 16 23 302
03 10 17 24 313
04 11 18 254
05 12 19 265
06 13 20 276

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. 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 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.
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.
Common yearsLeap yearsAll years
JanOct0
May1
FebAug2
FebMar Nov3
Jun4
Sept Dec5
JanApr July6

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, 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 for March to December.
2025 is a common year starting on Wednesday, which means that it corresponds to the 2014 calendar year. The first two months of 2025 correspond to the first two months of 2020. 2026 is a common year starting on Thursday, which means that it corresponds to the 2015 calendar year. The last ten months of 2026 correspond to the last ten months of 2020. 2027 is a common year starting on Friday, which means that it corresponds to the 2021 calendar year. 2028 is a leap year starting on Saturday, which means that it corresponds to the 2000 calendar year. The first two months of 2028 correspond to the first two months of 2022. The last ten months of 2028 correspond to the last ten months of 2023.
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 Monday was 2024 and the next occurrence will be 2052. Likewise, the next common years starting on Wednesday will be 2031, 2042, and then 2053. Both of these statements are true unless a leap year is skipped, of which will not happen until 2100.
For details, see the table below:
Year of the
century mod 28
00 06 12 17 230
01 07 12 18 241
02 08 13 19 242
03 08 14 20 253
04 09 15 20 264
04 10 16 21 275
05 11 16 22 006

Notes:
  • Black means all the months of a common yearRed means the first two months of a leap yearBlue means the last ten months of a leap year

Corresponding centuries

Julian century
mod 700
Gregorian century
mod 400
Day
400: 1100 1800...300: 1500 1900...Sun
300: 1000 1700...Mon
200 0900 1600...200: 1800 2200...Tue
100 0800 1500...Wed
700: 1400 2100...100: 1700 2100...Thu
600: 1300 2000...Fri
500: 1200 1900...000: 1600 2000...Sat

"Year 000" is, in normal chronology, the year 1 BC. In astronomical year numbering the year 0 comes between 1 BC and AD 1. In the proleptic Julian calendar,, 1 BC starts on Thursday. In the proleptic Gregorian calendar,, 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 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,. 20 indicates that 2000 is a leap year. Use Jan and Feb only in leap years.
For determination of the day of the week
  • the day of the month: 1 ~ 31
  • the month:
  • the year:
  • the century mod 4 for the Gregorian calendar and mod 7 for the Julian calendar .
  • 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 = mod 7.

Revised Julian calendar

Note that the date 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 by seven and divide the product by nine. Note the quotient. Enter the table with the Julian year, and just before the final division add 50 and subtract the quotient noted above.
The following is an example of calculating the day of the week for 27 January 8315:
= 2015, = 1915, = 19 remainder 15, = 133, = 14 remainder

Dominical letter

To find the dominical letter, calculate the day of the week for either 1 January or 1 October, and assign a letter with Sunday corresponding to A, Saturday corresponding to B,... and Monday corresponding to 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.
In the Revised Julian calendar – all years which divide exactly by 100.

The Doomsday

The Doomsday algorithm is an artefact of recreational mathematics.

Result

The following is a table for finding the day of the week without calculation.
Examples:
  • For common method
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 is in row D and the letter C in the year row is located in column G. 18 is in row C and the letter in the century row and column G is B, so the day of the week is Tuesday.
October 13 is a F day. The letter F in the year row is located in column G. The letter in the century row and column G is E, so the day of the week is Friday.
January 1 corresponds to G, G in the year row corresponds to F in the century row, and F corresponds to Saturday.
A pithy formula for the method: "Date letter, letter is in year row for the letter in century row, and for the day, the letter become weekday ".

The Sunday letter method

Each day of the year 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 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 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 Rata Die 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.
For example, the date of 13 August 2009 is 733632 days from 1 January AD 1. Taking the number mod 7 yields 4, hence a Thursday.

Gauss's algorithm

Carl Friedrich Gauss 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's method was applicable to the Gregorian calendar. He numbered the weekdays from 0 to 6 starting with Sunday. He defined the following operation.
; Inputs
; Output
; Procedure
MonthsJanFebMarAprMayJunJulAugSepOctNovDec
Common years033614625035
Leap years034025036146

The above procedure can be condensed into a single expression for the Gregorian case:

Worked example

For year number 2000,, and, the weekday of 1 January is
For example, the weekdays for 30 April 1777 and 23 February 1855 are
and

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 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
where
  • is the day of the month
  • is the shifted month
  • is the year unless is 11 = January or 12 = February which are considered part of the preceding year, giving
  • is the century given by
  • is the year relative to the century, given by, or simply the last 2 digits of
  • is the day of the week
MonthsMarAprMayJunJulAugSepOctNovDecJanFeb
Offset257101215182023252831

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

where
  • is the day of the month
  • is the shifted month
  • is the year unless is 13 = January or 14 = February which are considered part of the preceding year giving
  • is the century given by
  • is the year relative to the century, given by, or simply the last 2 digits of
  • is the day of week
MonthsMarAprMayJunJulAugSepOctNovDecJanFeb
Offset101315182023262831333639

The only difference is one between Zeller's algorithm and the Disparate Gaussian algorithm, that is.

Wang's algorithm

Wang's algorithm for human calculation of the Gregorian calendar is

where
  • is the last digit of the year ''
  • is the second last digit of the year
  • is the century, given by
  • is the day of the month
  • is the month
  • is the day of the week
  • is the null-days function with values listed in the following table
An algorithm for the Julian calendar can be derived from the algorithm above
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,
so is between 0 and 99. For,
The formula for the day of the week is
where the positive modulus is chosen.
The value of is obtained from the following table:
123456789101112
032503514624

The value of is obtained from the following table, which depends on the calendar. For the Gregorian calendar,
0123
0531

For the Julian calendar,
0123456
5432106

Lewis Carroll's method

Charles Lutwidge Dodgson 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 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.
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.
Century-item: For 'Old Style' subtract from 18. For 'New Style' divide by 4, take overplus from 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", 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.
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. "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".
Dates before 1752 would in England be given Old Style with 25 March as the first day of the new year. Carroll's method however assumes 1 January as the first day of the year, thus he fails to arrive at the correct answer, namely "Friday".
Had he noticed that 1676, February 23 is actually 1677, February 23, he would have accounted for differing year numbers—just like George Washington's birthday differs—between the two calendars. Then his method yields:
;1677, February 23
16 from 18 gives "2" 77 is 6 dozen and 5, giving 11; plus 1 gives 12, i.e. "5". Total "7" The item for February is "3". Total 10, i.e. "3" 23 gives "2". Total "5". Answer, "Friday".
It is noteworthy that those who have republished Carroll's method have failed to point out his error, most notably Martin Gardner.
In 1752, the British Empire abandoned its use of the Old Style Julian calendar upon adopting the Gregorian calendar, which has become today's standard in most countries of the world. For more background, see Old Style and New Style dates.

Methods in computer code

Keith

In the C language expressions below, y, m and d are, respectively, integer variables representing the year, month and day of the month.

% 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. On Motorola 68000-based devices, there is similarly less need of either processor registers 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 function. With minor changes, it was adapted for other high level programming languages such as APL2. Posted by Tomohiko Sakamoto on the comp.lang.c Usenet newsgroup in 1992, it is accurate for any Gregorian date.

dayofweek /* 1 <= m <= 12, y > 1752 */

It returns 0 = Sunday, 1 = Monday, etc.
Sakamoto also simultaneously posted a more obfuscated version:

dow

This version encodes the month offsets in the string and as a result requires a computer that uses standard ASCII to run the algorithm correctly, reducing its portability. In addition, both algorithms omit type declarations, which is allowed in the original K&R C but not allowed in ANSI C.

Gauss's method in MATLAB

% example date input
y1 = 2022;
m1 = 1;
d1 = 1;
month_offset = ; % common year
% offset if y1 leap year
if mod0 && mod0 && mod0
month_offset=; % leap year
end
% Gregor
weekday_gregor = rem + 5*rem + 4*rem + 6*rem
% Julian
weekday_julian = rem + 3*

0: Sunday 1: Monday.. 6: Saturday

Gauss's method for Gregorian calendar in Python


from numpy import remainder as rem
def is_leap_year -> bool:
"""Determine whether a year is a leap year."""
return year % 4 0 and

def day_of_week -> str:
"""Return day of week of given date as string,
using Gauss's algorithm to find it."""
if is_leap_year:
month_offset =
else:
month_offset =
y -= 1
wd = int + 4 * rem \
+ 6 * rem)

return