← Back to Blog

Calculating the day of the week in your head

If you’re reading this article, you’re probably wondering how to quickly calculate the day of the week for any given date in your head. In this article, you’ll learn how to do it.

What do I need to know?

Not really much…

  • Mental arithmetic
  • Addition (adding numbers in the range between 0 and 99)
  • Dividing numbers by 4
  • Modulo calculation (what is the remainder of a division?)
  • Memorizing a few numbers

Memorization

The following mappings of numbers to weekdays and months should be memorized:

Weekdays

For weekdays, it’s pretty simple. We start with Sunday = 0 and for each weekday after that, we add +1.

WeekdayNumber
Sunday0
Monday1
Tuesday2
Wednesday3
Thursday4
Friday5
Saturday6

Months

For months, it’s more difficult. Here, 12 numbers need to be memorized.

MonthNumberMonthNumber
January6July5
February2August1
March2September4
April5October6
May0November2
June3December4

Calculation

The formula for calculating the day of the week is:

WEEKDAY_CODE = (day_code + month_code + year_code + century_code) modulo 7

The WEEKDAY_CODE corresponds to the value from the weekday table. If the result is 4, i.e. WEEKDAY_CODE = 4, then the day of the week is Thursday.

But what are day_code, month_code, year_code and century_code?

Everything in this chapter that follows is based on the date 30.10.2019.

Day code

The day_code is very simple. It corresponds to the day of the month. For our example date 30.10.2019, the day code would therefore be 30.

Month code

The month_code is derived from the month table above. For our example date 30.10.2019, the month code would be 6, because the month is October.

Year code

The calculation of the year_code is more complex. For this, we ignore the century and millennium, as these are only relevant when calculating the century_code.

From the year 2019, we are only interested in 19. We divide this 19 by 4 without remainder, i.e. 19 / 4 = 4. We then add the obtained number back to the original year, i.e. 19 + 4 = 23.

This 23 is the year code.

The general formula is:

x = (year modulo 100) / 4
year_code = year + x

Century code

Most of the time, the day of the week of a date between 1900 and 2100 is asked. Less often, perhaps between 1600 and 2200.

Since those are only a few centuries, it is recommended to memorize at least the century_codes of the current and the last century:

CenturyCentury code
16__0
17__5
18__3
19__1
20__0
21__5
22__3

For years between 2000 and 2099 (including our example 30.10.2019), the century_code is therefore 0.

A more general formula for this is century_code = (3 - (century modulo 4)) * 2. Note: Century here always refers to the first two digits of the year representation (e.g. for 1943, that would be 19).

Calculating the day of the week

We have now calculated 4 codes:

  • day_code = 30
  • month_code = 6
  • year_code = 23
  • century_code = 0

We can now plug these into our formula from above:

WEEKDAY_CODE = (day_code + month_code + year_code + century_code) modulo 7
WEEKDAY_CODE = (30 + 6 + 23 + 0) modulo 7
WEEKDAY_CODE = 59 modulo 7
WEEKDAY_CODE = 3

Looking at the weekday table above, we see that 3 stands for Wednesday. Wednesday is therefore the day of the week for 30.10.2019.

One single exception (leap years)

For leap years, this calculation would be wrong. But for leap years, we only need to do a little differently to get the correct result.

Procedure: If the year is a leap year and the month is January or February (only then), we change the formula above to:

WEEKDAY_CODE = (day_code + month_code + year_code + century_code - 1) modulo 7

So we simply subtract 1 from it.

Leap year rule:

  • Years divisible by 4 without remainder are leap years.
  • BUT: Years divisible by 100 without remainder are not leap years.
  • BUT: Years divisible by 400 without remainder are leap years after all.

What many people don’t know: The years 1800, 1900, 2100 and 2200 are therefore not leap years!

Examples

Example 1 (January 1st, 1902)

The century_code is 1.

The year_code is derived from:

2 / 4 = 0
2 + 0 = 2

The month_code is 6.

The day_code is 1.

1902 was not a leap year.

Plugged into the formula:

WEEKDAY_CODE = (day_code + month_code + year_code + century_code) modulo 7
WEEKDAY_CODE = (1 + 6 + 2 + 1) modulo 7
WEEKDAY_CODE = 10 modulo 7
WEEKDAY_CODE = 3

January 1st, 1902 was therefore a Wednesday.

Example 2 (June 10th, 2069)

The century_code is 0.

The year_code is derived from:

69 / 4 = 17
69 + 17 = 86

The month_code is 3.

The day_code is 10.

2069 is not a leap year.

Plugged into the formula:

WEEKDAY_CODE = (day_code + month_code + year_code + century_code) modulo 7
WEEKDAY_CODE = (10 + 3 + 86 + 0) modulo 7
WEEKDAY_CODE = 99 modulo 7
WEEKDAY_CODE = 1

June 10th, 2069 is therefore a Monday.

Example 3 (February 20th, 1996)

The century_code is 1.

The year_code is derived from:

96 / 4 = 24
96 + 24 = 120

The month_code is 2.

The day_code is 20.

1996 is a leap year and the month is February! So we need to subtract 1!

Plugged into the formula:

WEEKDAY_CODE = (day_code + month_code + year_code + century_code - 1) modulo 7
WEEKDAY_CODE = (20 + 2 + 120 + 1 - 1) modulo 7
WEEKDAY_CODE = 142 modulo 7
WEEKDAY_CODE = 2

February 20th, 1996 is therefore a Tuesday.

Example 4 (December 24th, 1644)

The century_code is 0.

The year_code is derived from:

44 / 4 = 11
44 + 11 = 55

The month_code is 4.

The day_code is 24.

1644 is a leap year, but the month is not January or February. So we don’t need to do anything further.

Plugged into the formula:

WEEKDAY_CODE = (day_code + month_code + year_code + century_code) modulo 7
WEEKDAY_CODE = (24 + 4 + 55 + 0) modulo 7
WEEKDAY_CODE = 83 modulo 7
WEEKDAY_CODE = 6

December 24th, 1644 was therefore a Saturday.

Tips for faster calculation

Instead of first adding all the numbers (day_code, month_code, year_code and century_code) and then computing modulo 7, you can also use modulo earlier to keep the numbers small.

Based on an extreme example (30.10.1999), you could proceed as follows:

99 / 4 = 24
24 modulo 7 = 3
99 + 3 = 102
102 modulo 7 = 32 modulo 7 = 4

30 modulo 7 = 2

WEEKDAY_CODE = (day_code + month_code + year_code + century_code) modulo 7
WEEKDAY_CODE = (2 + 6 + 4 + 1) modulo 7
WEEKDAY_CODE = 13 modulo 7
WEEKDAY_CODE = 6

That day was a Saturday.

Miscellaneous

A weekday challenger for practice: https://ndsvw.github.io/Which-day-of-the-week/

Which-day-of-the-week

World records in weekday calculation: http://www.recordholders.org/de/records/dates.html