Archive for February, 2021

Finding the Day of the Week by Hand

Posted: February 21, 2021 in Mathematics
Tags: ,

Have you wonder which day of the week your birth day is? For example, can you find what day of the week is April 1st, 1800? without flipping through the calendar or searching it on google? Okay, let’s find out.

Because the leap year day is added at the end of February, for the sake of convenience, assume each year ends at the end of February. So, we assign the value to the months as follow:

Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb
 1   2   3   4   5   6   7   8   9   10  11  12

And we want to assign a value to the weekday as follow:

Sun Mon Tue Wed Thu Fri Sat
 0   1   2   3   4   5   6

Since (the common year) 365 1 mod 7 and (the leap year) 366 2 mod 7, In every year, the day will be incremented by 1 day and 2 days for the common year and the leap year respectively. For instance, if D_{2000} is the weekday number for Mar 1, 2000, then the weekday number D_Y for Mar 1 of the year Y can be expressed as

D_Y \equiv D_{2000} + (Y - 2000) + L \pmod 7

where L is the number of leap years between Mar 1, 2000 and Mar 1 of the year Y.

To find L, we count the number of the years that are divisible by 4, minus the number of century years, and then add back the number of century years that are divisible by 400. To find out why, take a look at this link.

The number of years between 2000 and Y that are divisible by 4:

\displaystyle \left\lfloor\frac{Y-2000}{4}\right\rfloor = \left\lfloor\frac{Y}{4}-500\right\rfloor = \left\lfloor\frac{Y}{4}\right\rfloor - 500

The number of century years between 2000 and Y:

\displaystyle \left\lfloor\frac{Y-2000}{100}\right\rfloor = \left\lfloor\frac{Y}{100}-20\right\rfloor = \left\lfloor\frac{Y}{100}\right\rfloor - 20

The number of century years between 2000 and Y that are divisible by 400:

\displaystyle \left\lfloor\frac{Y-2000}{400}\right\rfloor = \left\lfloor\frac{Y}{400}-5\right\rfloor = \left\lfloor\frac{Y}{400}\right\rfloor - 5

So combining these, we get the number of leap years:

\displaystyle L = \left\lfloor\frac{Y}{4}\right\rfloor - 500 - \left(\left\lfloor\frac{Y}{100}\right\rfloor - 20\right) + \left\lfloor\frac{Y}{400}\right\rfloor -5 = \left\lfloor\frac{Y}{4}\right\rfloor - \left\lfloor\frac{Y}{100}\right\rfloor + \left\lfloor\frac{Y}{400}\right\rfloor- 485

Let’s flip through the calendar app, we find that Mar 1, 2000 is Wednesday. So D_{2000} = 3 and

\displaystyle D_{2021} \equiv 3 + (2021-2000) + \left\lfloor\frac{2021}{4}\right\rfloor - \left\lfloor\frac{2021}{100}\right\rfloor + \left\lfloor\frac{2021}{400}\right\rfloor- 485

\equiv 3 + 21 + 505 - 20 + 5 - 485 \equiv 1 \pmod{7}

So, Mar 1, 2021 is Monday.

Now, let’s denote

Y = 100c+y \qquad 0 \leq y < 100

then,

\displaystyle L = \left\lfloor\frac{100c+y}{4}\right\rfloor - \left\lfloor\frac{100c+y}{100}\right\rfloor + \left\lfloor\frac{100c+y}{400}\right\rfloor- 485

\displaystyle = 24c + \left\lfloor\frac{y}{4}\right\rfloor - \left\lfloor\frac{y}{100}\right\rfloor + \left\lfloor\frac{c}{4}+\frac{y}{400}\right\rfloor - 485

\displaystyle = 24c + \left\lfloor\frac{y}{4}\right\rfloor + \left\lfloor\frac{c}{4}\right\rfloor - 485

since \dfrac{y}{100} < 1 and \dfrac{y}{400} < \dfrac14. Then

\displaystyle D_Y \equiv 3 + (100c + y - 2000) + 24c + \left\lfloor\frac{y}{4}\right\rfloor + \left\lfloor\frac{c}{4}\right\rfloor - 485 \pmod 7

\displaystyle \equiv 3 + 5c + y + \left\lfloor\frac{y}{4}\right\rfloor + \left\lfloor\frac{c}{4}\right\rfloor \pmod 7

Next, we are going to find out the day of the week on which the first of each month of the year would fall. Since 30 2 mod 7 and 31 3 mod 7, the table below shows that the day number to be added to the first day of each month in the year Y.

31  30  31  30  31  31  30  31  30  31  31  28
Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb
 0   3   5   8   10  13  16  18  21  23  26  29
  +3  +2  +3  +2   +3  +3  +2  +3  +2  +3  +3

Notice the pattern 3, 2, 3, 2, 3 repeats every 5 months, 13 days a period of every 5 months. With a little trial and error playing with the numbers, it’s not hard to figure out the following congruence:

\displaystyle \left\lfloor\frac{13m-1}{5}\right\rfloor-2 \pmod 7

Finally, we can find the day of the week of any given day d in the given month m of the given year y by the formula below:

\displaystyle day \equiv d-1 + \left\lfloor\frac{13m-1}{5}\right\rfloor -2+ D_Y \pmod 7

where \displaystyle D_Y = 3 + 5c + y + \left\lfloor\frac{y}{4}\right\rfloor + \left\lfloor\frac{c}{4}\right\rfloor

Or simply,

\displaystyle day \equiv d + \left\lfloor\frac{13m-1}{5}\right\rfloor + 5c + y + \left\lfloor\frac{c}{4}\right\rfloor + \left\lfloor\frac{y}{4}\right\rfloor \pmod 7

For example, if I want to find out the day of the week I was born, which is Feb 21, 1979, I need to enter d = 21, m = 12, c = 19, y = 78 (notice that we assume the month starts in March, where Feb 1979 is considered as the 12th month of 1978) into the formula above:

\displaystyle day \equiv 21 + \left\lfloor\frac{13(12)-1}{5}\right\rfloor + 5(19) + 78 + \left\lfloor\frac{19}{4}\right\rfloor + \left\lfloor\frac{78}{4}\right\rfloor \equiv 3 \pmod 7

Therefore, I know I was born on Wednesday 🙂