methods to calculate 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 … Wikipedia
🌐
Wikipedia
en.wikipedia.org › wiki › Determination_of_the_day_of_the_week
Determination of the day of the week - Wikipedia
January 21, 2026 - For year number 2000, A − 1 = 1999, Y − 1 = 99 and C = 19, the weekday of 1 January is ... The algorithm for the day-of-week of 1 Jan can be proven using modulo arithmetic. The main point is that because 365 % 7 = 1, each year adds 1 day to the progression.
🌐
John D. Cook
johndcook.com › blog › 2022 › 05 › 07 › day-of-the-week
Mentally calculating the day of the week
September 18, 2025 - The result is a number that tell you the day of the week. To be even more succinct, let y be the number formed by the last two digits of the date. Let d be the day of the month. Let L equal 1 if the year is a leap year and the date is in January or February and 0 otherwise. Then the algorithm above can be written as
Discussions

date - What is the easiest algorithm to find the day of week of day zero of a given year? - Stack Overflow
I am trying to figure out what the day of the week of day zero (January 1st) of a given year. So far I have looked at the Wikipedia page 'Calculating the day of the week' but I was wondering if th... More on stackoverflow.com
🌐 stackoverflow.com
A cool guide how to calculate the day of the week
I'll keep that in mind in case I'm ever in a black phoneless abyss More on reddit.com
🌐 r/coolguides
70
635
January 2, 2025
Understanding the algorithm behind day of week calculation - Computer Science Stack Exchange
I came across this algorithm recently to calculate day of the week for any year. int y0 = year - (14 - month) / 12; int x = y0 + y0/4 - y0/100 + y0/400; int m0 = month + 12*((14 - month)/12) - 2; ... More on cs.stackexchange.com
🌐 cs.stackexchange.com
June 19, 2018
Question Regarding to Conway's Doomsday Algorithm
It's because 2100 was not a leap year. So your final calculation is Tuesday + (8 + 4 + 0) = Sunday. Incidentally, the fastest method for performing calendar calculation is this one . I used this to obtain the British record (59 dates in one minute) and the same method is used by most other top calendar calculators. More on reddit.com
🌐 r/learnmath
2
2
December 10, 2022
🌐
University of Waterloo
cs.uwaterloo.ca › ~alopez-o › math-faq › node73.html
How to determine the day of the week, given the month, day and year
Because the leap year pattern also recurs with a four hundred year cycle, a simple table of four hundred elements, and single modulus, suffices to determine the day of the week (in the Gregorian Calendar), and does it much faster than all the other algorithms proposed.
🌐
Northern Illinois University
faculty.cs.niu.edu › ~hutchins › csci297p2 › webpages › zeller.htm
Zeller's Algorithm: Day of the Week
If Month is 1 or 2 Then A = Month+10 NewYear = Year - 1 Else A = Month-2 NewYear = Year End If B = Day C = which year of the century (that is, Mod(NewYear, 100)) D = which century (that is, NewYear / 100) W = (13 * A - 1) / 5 X = C / 4 Y = D / 4 Z = W + X + Y + B + C - 2 * D R = Mod(Z, 7) If R is less than 0 Then Add 7 to R End-If · At this point, R is an Integer value between 0 and 6, inclusive: R = 0 Sunday R = 1 Monday R = 2 Tuesday R = 3 Wednesday R = 4 Thursday R = 5 Friday R = 6 Saturday ... Suppose the date is December 2, 2009.
🌐
Reddit
reddit.com › r/coolguides › a cool guide how to calculate the day of the week
r/coolguides on Reddit: A cool guide how to calculate the day of the week
January 2, 2025 - The function is the same as the year offset part in the formula: (Y + Y//4 + B)%7. For instance, base year 2060 would have offset (60+60/4+0)%7=75%7=5 (here referring to the known 2000 base and its B=0). This also works for any year far above, ...
🌐
Wikipedia
en.wikipedia.org › wiki › Doomsday_rule
Doomsday rule - Wikipedia
January 8, 2026 - 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.
Find elsewhere
🌐
What the Day
whattheday.com
Learn the Doomsday algorithm
Performing the modulo operation, 13 modulo 7 is 6, which is Saturday. Therefore, the key to mastering the doomsday algorithm lies in getting comfortable with quickly performing these modulo operations.
🌐
HackerEarth
hackerearth.com › home › blog › algorithm on how to find the day of a week
Algorithm on how to find the day of a week
May 23, 2019 - This algorithm uses the formula: (d + m + y + [y/4] + c) mod 7 · Here, d is the day, m is the month, y is the year, and c is the century number. Each weekday is assigned a number using modulo 7. For instance: ... Common years have 365 days, ...
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › tomohiko-sakamotos-algorithm-finding-day-week
Tomohiko Sakamoto's Algorithm- Finding the day of the week - GeeksforGeeks
August 10, 2022 - # A Python 3 program to implement # the Tomohiko Sakamoto Algorithm # function to implement tomohiko # sakamoto algorithm def day_of_the_week(y, m, d) : # array with leading number of days values t = [ 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 ] # ...
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › find-day-of-the-week-for-a-given-date
Find day of the week for a given date - GeeksforGeeks
February 14, 2025 - The formula: (y + y/4 − y/100 + y/400 + t[m−1] + d) % 7 calculates the day of the week by summing the day (d), month code (t[m - 1]), and adjusted year values. The result is then taken modulo 7, which gives a value between 0 and 6, corresponding ...
🌐
OpenGenus
iq.opengenus.org › algorithm-for-day-of-week
Algorithms for Calculating Day of Week
December 5, 2020 - Days in current month is d. Now using the formula (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7 gives the day for the particular date. Here is the link to a more detailed article about Tomohiko Sakamoto Algorithm · Using the Georgian Calender in this weekdays are numbered from 0 to 6.
🌐
Fandom
calendars.fandom.com › wiki › Calculating_the_day_of_the_week
Calculating the day of the week | Calendar Wiki | Fandom
January 9, 2026 - The basis of nearly all the algorithms to calculate the day of the week is: Use arithmetic modulo 7 to add the number of days elapsed since the start of a known period (usually in practice a century).
🌐
DZone
dzone.com › data engineering › ai/ml › algorithm of the week: how to determine the day of the week
Algorithm of the Week: How to Determine the Day of the Week
April 24, 2012 - Because of leap years we can have a year starting on one of the seven days of the week and to be either leap or common. This means just 14 combinations. Following these observations we can refer to the following table. ... Here’s the month table. Columns 2 and 3 differs only for January and February. ... Now let’s go back to the algorithm.
Top answer
1 of 1
7

As mentioned in a comment, this program is a variant on Zeller's congruence.

Here are the steps:

  1. It's good to know that the Gregorian calendar (which is what we are using) repeats every 400 years. In the 400 year cycle, every fourth year is a leap year except for the centuries other than the one at the start of the cycle. In other words, in the 400-year cycle starting 2000 and ending 2399, there are 97 leap years: all the years divisible by 4 except 2100, 2200 and 2300.

    There are 365 days in a normal year, which is 52 weeks and one day. A leap year has an extra day. So the 400-year cycle, which has 303 normal years and 97 leap years, is 52400 weeks plus (303 + 972 = 497) days. 497 days is exactly 71 weeks, so the cycle is an exact number of weeks, which means the weekday for a given date is the same for the "same date" in every cycle. (The same date meaning the same day, month and year mod 400.)

    Since we're only interested in which weekday a date is, and not the total number of days since some determined starting point, we can do all computations mod 7. So if we know the weekday for some particular date, we can find the weekday for the same day/month in another year by adding the number of years and then the number of intervening leap days.

     int x = y0 + y0/4 - y0/100 + y0/400;
    

    y0 is explained below; if you think of it as the number of years from the beginning of (some) 400 year-cycle, then x is just the number of years plus the number of leap years: y0/4 (every fourth year) - y0/100 (except for centuries) + y0/400 (other than the centuries which start a cycle). If we had computed y0 as years into the current cycle, we could have avoided the y0/400 term.

  2. The fact that a leap day falls into the middle of a year complicates that computation. To make it simpler, we start the cycle at March 1 instead of January 1, effectively moving January and February to the previous year. That puts the leap day at the end of the year, so we can evaluate the number of leap days by counting the number of leap years, as above. As we'll see below, this also has the advantage of making the alternation of month lengths more regular; aside from February, months more or less alternate between 31 and 30 days.

     int y0 = year - (14 - month) / 12;
     int m0 = month + 12*((14 - month)/12) - 2;
    

    Those lines are trying to way too hard to be clever, and end up being terrible because of the slowness of division (even though division by 12 can be performed with multiplies, and even though the compiler can figure out that it's only necessary to do it once. The code would be clearer and faster if it were written in the obvious way:

     int y0 = year, m0 = month - 2;
     if (m0 < 1) { --y0; m0 += 12; }
    
  3. Essentially, we now have a weekday offset of March 1 in the specified year from the March 1 which starts the cycle. Now we just need to figure out the adjustment for the months between March and the specified month. Each of these months will move the weekday by either two (30 mod 7) or three (31 mod 7) days. Months mostly alternate between 31 and 30 days, except although sometimes there are two 31-day months in a row. (As mentioned above, we can ignore February here because we're only counting months which come before the specified date, and with February shifted to the end of the year, it is never before any date in the year.)

     int d0 = (date + x + (31*m0)/12)%7;
    

    (31 * m0) / 12 for m0 in the range [1, 12] produces the sequence {2, 5, 7, 10, 12, 15, 18, 20, 23, 25, 28, 31}. The adjacent differences in that sequence are {3, 2, 3, 2, 3, 3, 2, 3, 2, 3, 3} which happen to correspond to the lengths of the months (mod 7) starting at March. (The pairs of consecutive 3s correspond to July/August and December/January.) So adding this to the year adjustment x and the date in the month date and then reducing the sum mod 7 gives us the day in the week with the week starting three days before March 1 of (every) cycle. (Three days before because (1) the magic formula (31 * m0) / 12 starts with 2, not 0, and (2) the day of the month starts with 1, not 0. So the formula is off by 3.)

    This is not the only way of performing this calculation. As it happens, exactly the same sequence is produced with (13 * m0 - 1) / 5. Either way, the cleverness is not justified by efficiency; division is a lot slower than a simple table lookup:

     /* Not optimal but it corresponds to the above computation */
     static const char month_adjust[] = { 
         2, 5, 7, 10, 12, 15, 18, 20, 23, 25, 28, 31
     };
     int d0 = (date + x + month_adjust[m0]) % 7;
    

    The above table could be reduced to three bits per month, since only the value mod 7 is important. That means that the lookup table could be replaced with a magic integer constant and a bit-shift, but the potential gain is probably insignificant. I'll leave the details as an exercise for would-be code golfers.

  4. March 1 of every cycle is a Wednesday, and that needs to correspond to the value 3 of that computation. The mapping between modulo and day of the week is provided by the switch statement:

     switch (d0) {
         case 1: return "Monday";
         case 2: return "Tuesday";
         case 3: return "Wednesday";
         case 4: return "Thursday";
         case 5: return "Friday";
         case 6: return "Saturday";
         case 0: return "Sunday";
     }
    

    I would have used a lookup table instead of a switch, which leads to more direct code:

     static const char* weekdays = { 
         "Sunday", "Monday", "Tuesday",
         "Wednesday", "Thursday",
         "Friday", "Saturday"
     };
     return weekdays[d0];
    
🌐
Time and Date
timeanddate.com › calculators › doomsday algorithm
The Doomsday Algorithm - Calculating the Weekday ...
You know the doomsday of the year (in 1978, it was Tuesday), and you know which dates of the year are doomsdays. Now you can simply use the doomsday closest to the date in question to find out which weekday it falls on.
🌐
Utexas
quasar.as.utexas.edu › BillInfo › doomsday.html
What is the day of the week?
This is really a nice trick. You can easily calculate the day of the week, given any date in history, and with a little practice you can even do it in your head. The method is based on one developed by John Horton Conway, and is described in Winning Ways, a book that he wrote with Berlekamp and Guy.
🌐
Art of Memory
artofmemory.com › blog › how-to-calculate-the-day-of-the-week
How to Calculate the Day of the Week from Any Date | Art of Memory
April 10, 2023 - The tool only calculates years from 1700 to 2399, but that should provide enough examples to teach you the algorithm. When the calendar switched from Julian to Gregorian, 11 days disappeared, so there are no dates between September 3, 1752 and September 13, 1752. ... Take ‘69 and divide by 4, discarding the remainder. That leaves 17. Add 69 to 17 to get 86. Then, 86 mod 7 = 2. The Year Code is 2. The Month Code for July is 6. The Century Code for the 1900s is zero. The Date Number is 20, because it’s the 20th of July.
🌐
Academia.edu
academia.edu › 31413474 › Algorithm_to_calculate_the_day_of_the_week
(PDF) Algorithm to calculate the day of the week
January 1, 2017 - The date, which identifies each day with three integers, year/month/day, gives no indication on the periods of the two calendars and on the day of the week, essential in some cases, for instance, whether it is a holiday or a working day. The following is an algorithm, easy to implement, which relates the calendar date with the day of the week and the periods of the Julian and Gregorian calendar, through two procedures: End-year method and March-first method.
🌐
Davecturner
davecturner.github.io › 2021 › 12 › 27 › doomsday-rule.html
The Doomsday rule: mental day-of-week calculations | David Turner says…
December 27, 2021 - The Doomsday rule is an algorithm for working out the day of the week of a given date. It’s based on John Conway’s observation that certain memorable dates called doomsdays (4/4, 6/6, 8/8, 10/10, 12/12, 9/5, 5/9, 7/11, 11/7, …) always occur on the same day of the week in any given year.