Mentally calculating the day of the week

In my previous post I mentioned John Conway’s Doomsday rule for calculating the day of the week for any date. This method starts off very simple, but gets more complicated when you actually use it.

This post will present an alternative method that’s easier to use in practice and can be described more succinctly.

Here’s the algorithm.

  1. Take the last two digits of the year and add the number of times 4 divides that number.
  2. Add a constant corresponding to the month.
  3. Add the day of the month.
  4. Subtract 1 in January or February of a leap year.
  5. Take the remainder by 7.

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

(y + ⌊y/4⌋ + dL + month constant) % 7.

Here ⌊x⌋ is the floor of x, the greatest integer no greater than x, and x % 7 is the remainder when x is divided by 7.

Update: There are multiple ways to compute the year share, i.e. y + ⌊y/4⌋, that are equivalent mod 7 and easier to carry out mentally than the direct approach.

I’ve deliberately left out a couple details above. What are these month constants, and how does the number at the end give you a day of the week?

Customizing for the 21st century

I learned the method above in the 20th century, and the rule was optimized for the 20th century. You had to subtract 1 for dates in the 21st century.

Also, when I learned the method, it numbered the days of the week with Sunday = 1, Monday = 2, etc. Now I would find it easier to start with Sunday = 0.

Here’s an updated table of month constants that eliminates the need to adjust for dates in the 20th century, and numbers the days of the week from 0.

    | January | 6 | February | 2 | March     | 2 |
    | April   | 5 | May      | 0 | June      | 3 |
    | July    | 5 | August   | 1 | September | 4 |
    | October | 6 | November | 2 | December  | 4 |

If you’d like to number Sunday as 1 rather than 0, add 1 to all the numbers above.

The article I learned this method from came with suggested mnemonics for remembering the month constants. But when you change the constants like I’ve done here, you have to come up with new mnemonics.

Examples

I’m writing this post on Saturday, May 7, 2022. Let’s verify that the method gives the correct day of the week today.

Start with 22, and add 5 because ⌊22/4⌋ = 5. The number for May is 0, so there’s nothing to add for the month. We add 7 because today’s the 7th. This gives us

22 + 5 + 7 = 34

which gives a remainder of 6 mod 7, so this is day 6. Since we started with 0 for Sunday, 6 is Saturday.

Next, let’s do January 15, 2036. We get

36 + 9 + 6 + 15 − 1 = 65

which is 2 mod 7. so January 15 will fall on a Tuesday in 2036. Note that we subtracted 1 because 2036 will be a leap year and our date is in January.

If we want to look at Christmas 2036, we have

36 + 9 + 4 + 25 = 74

which is 4 mod 7, so December 25 will fall on a Thursday in 2036. We didn’t subtract 1 because although 2036 is a leap year, we’re looking at a date after February.

Other centuries

For dates in the 20th century, add 1.

For dates in the 22nd century, subtract 2.

If by some reason you’re reading this article in the 22nd century, make your own table of month constants by subtracting 1 from the numbers in the table above.

Update: See this post for more detail on working with other centuries.

More details

When I was at University of Texas, humanities majors had to take a class we called “math for poets.” The class was a hodgepodge of various topics, and the most popular topic when I taught the class was this method. Here’s a handout I gave the class.

That handout is a little slower paced than this blog post, and goes into some explanation for why the method works. (The method was meant to motivate modular arithmetic, one of the topics on the syllabus, so explaining why the method works was secretly the whole point of teaching it.)

The handout is still valid. You can follow it verbatim, or you can replace the table of month constants with the one above and ignore the 21st century correction step.

Related posts

Cubic calendars

Suppose you’re tasked with designing a Christmas countdown figure that uses numbered cube faces.

Christmas countdown Santa

How would you put the numbers on the cubes?

Suppose you want the calendar to say “00” on Christmas Day. If we were accustomed to counting in base six, you could label the sides of each cube 0 through 5, and you could count up to 55six = 35ten days until Christmas. But let’s work in base 10 like nearly all humans do.

We would at least like to count to 24 so we could start using our calendar on December 1. But to count up to 24, we have to get past 22. That means we have to represent 00, 11, and 22, and that means we have to put a 0, 1, and 2 on each cube. But then we have six remaining faces to receive seven remaining digits, so we can’t get past 22.

Here’s where we break our implicit rules. We’ve tacitly assumed each face of each cube has only one label. But since a ‘6’ is an upside-down ‘9’, we can effectively put seven labels on six faces. One cube, call it cube A, can be labeled 0, 1, 2, 3, 4, and 5, and the other, call it cube B, can be labeled 0, 1, 2, 6 (9), 7, and 8.

We can put cube B first on 0, and use cube A to count up to 5. Then we put cube A first on 0 and use cube B to count from 6 up to 9 (upside-down 6). We can do the analogous procedure for leading digits 1 and 2 to count all the way up to 29. To count any further we have to put cube A first with 3 showing because that’s the only way to get a number in the 30s. We can count up to 32, then we’re stuck.

We could break another implicit rule. We’ve assumed there must be two digits. What if we’re content to have a single 0 on Christmas Day and represent single digits by not using a cube in the first slot? Now only one cube has to have a 0 on it.

I don’t think this helps. To get past 32, we need a 3 on both cubes. We already have a 3 on cube A, but if we replace the 0 on cube B with a 3, now we can’t represent 10 or 20.

So it seems 32 is as high as we can count without thinking of another rule to bend.

Exercise for the reader: How many consecutive numbers could you produce using octahedra rather than cubes? Since the sides of octahedra are triangles, not cubes, you might argue that the faces should be oriented with the base of the triangle on bottom and so the trick of using an upside-down 6 to represent 9 should be disallowed.

Leap seconds

world clock

We all learn as children that there are 60 seconds in a minute, 60 minutes in an hour, 24 hours in a day, and 365 days in a year.

Then things get more complicated. There are more like 365.25 days in a year, hence leap years. Except that’s quite right either. It’s more like 365.242 days in a year, which is why years divisible by 100 do not have leap years unless they’re also divisible by 400. So even though 2000 was a leap year, 2100 will not be.

The ratio of the time it takes Earth to circle the sun to the time it takes it to rotate on its axis is not an integer, and not even a nice fraction. Why should it be? It’s convenient that the ratio is approximately 365 ¼, and that’s good enough for many purposes, but that’s not the full story. And not only is the ratio not a nice fraction, it’s not even constant!

The earth’s rotation is slowing imperceptibly. Atomic clocks made is possible to measure how much it’s slowing down, but also make it necessary to measure. Now that atomic time is widely used, say to synchronize computer networks, the discrepancy between atomic time and astronomical observation matters.

Leap seconds have been inserted into the year occasionally to keep atomic time in sync with time relative to Earth’s rotation. These cannot be inserted on a regular basis like leap days because the change in Earth’s rotation is not regular. So committees have to decide how and when to insert leap seconds, and the process can be surprisingly acrimonious.

Unix time

It is often said that Unix time is the number of seconds since the “Epoch,” midnight of January 1, 1970. But it’s not that simple because leap seconds are not included.

Suppose you were in London a few weeks ago. If you were sitting at a Linux command prompt to ring in the New Year and typed

    date +%s

at the stroke of midnight, the result would have been 1577836800. This number factors as

1577836800 = 60 × 60 × 24 × (365 × 50 + 12)

corresponding to the number of seconds in a day times the number of days since New Year’s Day 1970, including 12 leap days. However, if a device with an atomic clock beeped once per second since the Epoch, it would beep for the 1577836827th time as 2020 began because there have been 27 leap seconds since then.

International Atomic Time

If you don’t want to deal with Daylight Saving Time, you can use Universal Coordinated Time (UTC) [1]. If you want to go a step further and not deal with leap seconds, then International Atomic Time (TAI) is for you [2].

With TAI, every day has exactly 86,400 seconds by definition. When that many seconds pass, it’s a new day. Makes things very simple, as long as you don’t have to make reference to UTC, which tries to accommodate Earth’s rotation.

At the moment, TAI is 37 seconds ahead of UTC. There have been 27 leap seconds since leap seconds were first instituted, and TAI started out 10 seconds ahead. The next time we add a leap second [3], TAI will be ahead by 38 seconds.

More posts on time

[1] Why is this not UCT? Because the French wanted to call it TUC for temps universel coordonné. The compromise was UTC, which doesn’t make sense in English or French.

[2] The French won this battle: TAI stands for temps atomique international.

[3] There are proposals to stop adding leap seconds, though the issue has been contentious. Maybe we won’t add any more leap seconds. Or maybe we’ll let them accumulate and add them all in at once, analogous to when several days were removed when converting from the Julian calendar to the Gregorian calendar.

Safe Harbor and the calendar rollover problem

elderly woman

Data privacy is subtle and difficult to regulate. The lawmakers who wrote the HIPAA privacy regulations took a stab at what would protect privacy when they crafted the “Safe Harbor” list. The list is neither necessary or sufficient, depending on context, but it’s a start.

Extreme values of any measurement are more likely to lead to re-identification. Age in particular may be newsworthy. For example, a newspaper might run a story about a woman in the community turning 100. For this reason, the Safe Harbor previsions require that ages over 90 be lumped together. Specifically,

All elements of dates (except year) for dates that are directly related to an individual, including birth date, admission date, discharge date, death date, and all ages over 89 and all elements of dates (including year) indicative of such age, except that such ages and elements may be aggregated into a single category of age 90 or older.

One problem with this rule is that “age 90” is a moving target. Suppose that last year, in 2018, a data set recorded that a woman was born in 1930 and had a child in 1960. This data set was considered de-identified under the Safe Harbor provisions and published in a medical journal. On New Year’s Day 2019, does that data suddenly become sensitive? Or on New Year’s Day 2020? Should the journal retract the paper?!

No additional information is conveyed by the passage of time per se. However, if we knew in 2018 that the woman in question was still alive, and we also know that she’s alive now in 2019, we have more information. Knowing that someone born in 1930 is alive in 2019 is more informative than knowing that the same person was alive in 2018; there are fewer people in the former category than in the latter category.

The hypothetical journal article, committed to print in 2018, does not become more informative in 2019. But an online version of the article, revised with new information in 2019 implying that the woman in question is still alive, does become more informative.

No law can cover every possible use of data, and it would be a bad idea to try. Such a law would be both overly restrictive in some cases and not restrictive enough in others. HIPAA‘s expert determination provision allows a statistician to say, for example, that the above scenario is OK, even though it doesn’t satisfy the letter of the Safe Harbor rule.

More privacy posts

Calendars and continued fractions

Calendars are based on three frequencies: the rotation of the Earth on its axis, the rotation of the moon around the Earth, and the rotation of the Earth around the sun. Calendars are complicated because none of these periods is a simple multiple of any other. The ratios are certainly not integers, but they’re not even fractions with a small denominator.

As I wrote about the other day in the context of rational approximations for π, the most economical rational approximations of an irrational number come from convergents of continued fractions. The book Calendrical Calculations applies continued fractions to various kinds of calendars.

Ratio of years to days

The continued fraction for the number of days in a year is as follows.

365.2424177 = 365 + \cfrac{1}{4 + \cfrac{1}{7+ \cfrac{1}{1 + \cfrac{1}{2 + \cfrac{1}{1 + \cfrac{1}{5 + \ldots }}}}}}

This means that the best approximations for the length of a year are 365 days plus a fraction of 1/4, or 7/29, or 8/33, or 23/95, etc.

You could have one leap day every four years. More accurate would be 7 leap days every 29 years, etc. The Gregorian calendar has 97 leap days every 400 years.

Ratio of years to months

If we express the ratio of the length of the year to the length of the month, we get

\frac{365.24244}{29.53059} = 12 +\cfrac{1}{2 + \cfrac{1}{1+ \cfrac{1}{2 + \cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{18 + \cfrac{1}{3 + \ldots }}}}}}}

By taking various convergents we get 37/3, 99/8, 136/11, etc. So if you want to design successively more accurate lunisolar calendars, you’d have 37 lunar months every 3 years, 99 lunar months every 8 years, etc.

Related posts

Another math calendar from Ron Doerfler

Last year Ron Doerfler made a beautiful calendar with images from graphical computing, charts used as computational aids before desktop calculators were ubiquitous.

Ron has made a new calendar and this year’s theme is lightning computing, tricks for mental calculation. The calendar is available for download as a PDF or for purchase in hard copy.

first pages from calendar

April calendar

Related post:

Calendars, Connections, and Cats

Logo from Broadway musical Cats

James Burke had a television series Connections in which he would create a connection between two very different things. For example, in one episode he starts with the discovery of the touchstone for testing precious metals and tells a winding tale of how the touchstone led centuries later to the development of nuclear weapons.

I had a Connections-like moment when a calendar led to some physics, which then lead to Andrew Lloyd Webber’s musical Cats.

A few days ago I stumbled on Ron Doerfler’s graphical computing calendar and commented on the calendar here. When I discovered Ron Doerfler’s blog, I bookmarked his article on Oliver Heaviside to read later. (Heaviside was a pioneer in what was later called distribution theory, a way of justifying such mathematical mischief as differentiating non-differentiable functions.) As I was reading the article on Heaviside, I came to this line:

At one time the ionosphere was called the Heaviside layer …

Immediately the lyrics “Up, up, up to the Heaviside layer …” started going through my head. These words come from the song “The Journey to the Heaviside Layer” from Cats. I had never thought about “Heaviside” in that song as being related to Mr. Heaviside. I’ve never seen the lyrics in print, so I thought the words were “heavy side” and didn’t stop to think what they meant.

Andrew Lloyd Webber based Cats on Old Possum’s Book of Practical Cats by T. S. Eliot. The song “The Journey to the Heaviside Layer” in particular is based on the poem Old Deuteronomy from Eliot’s book. Webber used the Heaviside layer as a symbol for heaven, based on an allusion in one of T. S. Eliot’s letters. The symbolism is obvious in the musical, but I hadn’t thought about “Heaviside layer” as meaning “the heavens” (i.e. the upper atmosphere) as well as heaven in the theological sense.

2010 calendar of lost mathematical art

Rod Carvalho wrote a post this morning announcing a beautiful 2010 calendar created by Ron Doerfler. Doerfler’s blog is entitled Dead Reckonings: Lost Art in the Mathematical Sciences. The calendar is an example of such lost art. It is illustrated with nomograms, ingenious ways of computing with graphs before electronic calculators were common. The illustrations are pleasant to look at even if you have no idea what they mean.

Image via Ron Doerfler.

Related posts

Spherical trig is a lost art. Why care about spherical trig?

The Gudermannian function gd(x) is another interesting relic of an early time. It is closely related to the Mercator projection and shows how to relate ordinary and hyperbolic trig functions without using complex numbers.

The image above shows solutions to the equation u + v + w = uvw. Here’s a post explaining the significance of that equation.