My teacher taught an expression to find the day of any date in the Gregorian calendar.


$$ \bbox[5px,border:2px solid red] { D\equiv {d+c_m+c_y+c+\left\lfloor\dfrac c4\right\rfloor \pmod7} } $$

Where $D$ is the day code of the given date and day can be found from the following table,$d$ is the date,$c$ is the last two digits of the year(ones and tens place digit),$c_m,c_y$ are given below.


Day code($D$): \begin{array}{|c|c|} \hline \mathrm{\color{red}{Day}}& \color{red}{\text{Day Code}}\\ \hline \mathrm{Sunday}&0\\ \hline \mathrm{Monday}&1\\ \hline \mathrm{Tuesday} &2\\ \hline \mathrm{Wednesday} &3\\ \hline \mathrm{Thursday} &4\\ \hline \mathrm{Friday}&5\\ \hline \mathrm{Saturday} &6\\ \hline \end{array}

Month code($c_m$):

For ordinary year: \begin{array}{|c|c|} \hline \color{red}{\text{January}}& \color{red}{\text{February}}&\color{red}{\text{March}}\\ \hline 1&4&4\\ \hline \color{red}{\text{April}}& \color{red}{\text{May}}&\color{red}{\text{June}}\\ \hline 0 &2&5\\ \hline \color{red}{\text{July}}& \color{red}{\text{August}}&\color{red}{\text{September}}\\ \hline 0 &3&6\\ \hline \color{red}{\text{October}}& \color{red}{\text{November}}&\color{red}{\text{December}}\\ \hline 1&4&6\\ \hline \end{array}

For leap year: \begin{array}{|c|c|} \hline \color{red}{\text{January}}& \color{red}{\text{February}}&\color{red}{\text{March}}\\ \hline 0&3&4\\ \hline \color{red}{\text{April}}& \color{red}{\text{May}}&\color{red}{\text{June}}\\ \hline 0 &2&5\\ \hline \color{red}{\text{July}}& \color{red}{\text{August}}&\color{red}{\text{September}}\\ \hline 0 &3&6\\ \hline \color{red}{\text{October}}& \color{red}{\text{November}}&\color{red}{\text{December}}\\ \hline 1&4&6\\ \hline \end{array}

Century code($c_y$): \begin{array}{|c|c|} \hline \color{red}{\text{Century Leap Year}}& \color{red}{\text{Century Code}}\\ \hline 1300&3\\ \hline 1400&1\\ \hline 1500&6\\ \hline 1600 &5\\ \hline 1700 &3\\ \hline 1800&1\\ \hline 1900 &6\\ \hline 2000&5\\ \hline \end{array}

More generalised Century code: \begin{array}{|c|c|} \hline {\color{red}{\text{Leap Year Century}}}& \color{red}{\text{Century Code}}\\ \hline \text{Leap Year Century}&5\\ \hline \text{Leap Year Century+100}&3\\ \hline \text{Leap Year Century+200}&1\\ \hline \text{Leap Year Century+300} &6\\ \hline \end{array}

He refused to give the derivation of the above expression(saying it won't be asked in the exam) but I can't use this expression without the derivation or without knowing how it works.

What I tried(think):

The denominator is $7$ because the numerator gives the total odd days(I think) and we have to find net odd days.

By observing, one can easily find that century code is two less than the number of odd days in a century.

For example: Number of odd days in $100$ years are $5$ and century for (leap year century $+ 100$ years) is $3$(that is $5-2$).

Number of odd days in $200$ years are $3$ and the century code for (leap year century$+200$ years) is $1$(that is $3-2$).

Number of odd days in 300 years are $1$ and the century code for (leap year century$+300$ years) is $6$(that is $1-2=-1$ and $7-1=6$ ).

The number of odd days in 400 years are $0$ and the century code for (leap year century) is ($0-2=-2$ and $7-2=5$)

I am unable to find any relation between odd days in the month and month code.

What is my question? How is this expression derived?

I am not able to derive the expression.



By leap year century, I meant century year ($1200,1300,1400$) which is a leap year(example $400,800,1200,1600$).

  • $\begingroup$ "I am unable to find any relation between odd days in month and month code." A month is $4*7 +k$ days. Jan has $31 = 28 + 3$ so the code for February is $3$ more than the code for Jan. Feb has $28$ days so the code for March is the same as the code from Feb. March has $31=28+3$ days so the code for Arpil would be $3$ more than the code for March but that would be $7$ and as the days of the week repeat ever $7$ days we reset to $0$. And so on. $\endgroup$
    – fleablood
    Nov 5, 2020 at 6:47
  • $\begingroup$ You don't divide by $7$. You take the remainder from dividing by $7$. $D\equiv {d+c_m+c_y+c+\left\lceil\dfrac c4\right\rceil}\pmod 7$. $\endgroup$
    – fleablood
    Nov 5, 2020 at 6:49
  • $\begingroup$ "Why the code of January is 1" WHy not? It's just the code that makes the first calculation Jan 1, 1301 work. $\endgroup$
    – fleablood
    Nov 5, 2020 at 7:23
  • $\begingroup$ Are you sure the formula is correct? for today (2020-11-05), we have $d=5, cm=4, cy=6, c=20, ceil=5$, the sum is $40$, and $40\equiv 5\pmod{7}$, but Friday $\ne$ Thursday... $\endgroup$
    – Déjà vu
    Nov 5, 2020 at 8:03
  • 1
    $\begingroup$ These things work better if the formulat is based on a March 1 through Feb 28/29 year. The ceiling function is odd to me. It adds a day for a leap year that is yet to come. It doesn't add the day for years ending in 00 which in general aren't leap years. But the leap year adjustment may take that into account. $\endgroup$
    – fleablood
    Nov 5, 2020 at 16:07

1 Answer 1



Let's choose our base starting point is Day 1 = Jan 1, 2000 (which was a leap year) and Day 0 = Dec 31, 1999. Day 0 was a Fri $=5$. So let $M_{2000} = 5$.

If we were asked what day of the week was the $k$th day of $2000$ that'd be easy. As the days repeat ever seven days we'd have $D = k + M_{2000}\pmod 7$.

And if we were asked what day of the week was Month $d$, 2000, we could calculate that $k = d + $ sum of the number of days in the months before Month $\pmod 7$.

So Jan $d$, 2000: $D = d + M_{2000}\pmod 7$.

Feb $d$, 2000: $D= d+ 31 +M_{2000}\equiv d+3 +M_{2000}\pmod 7$

March $d$, 2000: $D = d + 31 + 29 + M_{2000} \equiv d+ 4 + M_{2000}\pmod 7$

... and so on.

In general. Month $d$, 2000: $D= d+ c_m + M_{2000}\pmod 7$ where $c_m = $ sum of then number of in the months before Month $\pmod 7$.

Okay, so what about Month $d$, $20xx$?

In general a year has $365=52*7 + 1 \equiv 1 \pmod 7$ so if $D$ is the day of the week for Month $d$ $xxxx$ then the day of the week of Month $d$ $xxxx+1$ will be $365 + D \equiv 1+ D\pmod 7$. So if we completely ignored leap years we'd have:

Month, d, 20$xx$ would be $D= d + c_m + xx + M_{2000}\pmod 7$.

But we can't ignore leap years. We must add a day for every leap year encountered.

Okay.... bear with me.....

$2000$ was a leap year but we took that into account with the $c_m$s. So for $2000$ we don't make any adjustments. But to compare the dates of $2001$ to the dates of $2000$ the fact that $2000$ had $366 \equiv 2\pmod 7$ days means we must adjust and add $1$. They next time we adjust will be when we go from $2004$ to $2005$ and $2004$ also has $366$, not $365$ days.

so the formula is Month $d$, 20$xx$ would be $D = d + c_m +xx +\lceil \frac {xx}4\rceil + M_{2000}\pmod 7$.

But note, the $c_m$ codes were calculated for the year 2000 that was a leap year in which February has $29$ days. To adjust for years in which Feb has $28$ days we must increase $c_1$ and $c_2$ by $1$. (This is a little counter intuitive... but the days of 2001 after February have been adjusted by $01 + \lceil \frac {01}4\rceil = 2$ already but it is the days before February 29 that need adjusting because there is no Feb 29 in 2001 so all the days need to be pushed forward to fill the gap).

So we are $90\%$ of the way there.

Month $d$, 20$xx$ would be $D = d + c_m +xx +\lceil \frac {xx}4\rceil + M_{2000}\pmod 7$.

But what of other centuries?

Well, our formula $D = d + c_m +xx +\lceil \frac {xx}4\rceil + M_{mm00}\pmod 7$ would still work but for different values of $M_{mm00}$.

Now one ordinary century year has 100 years out of which 76 years are ordinary year and 24 years are leap year so odd days are 124($76 \times 1 +24\times 2)$. So $124\equiv 5\pmod 7$ days.

One leap century year has 75 ordinary years and 25 leap year so odd days are 125($75\times 1+25\times 2$) and $125\equiv 6\pmod 7$ days.

so as $M_{2000}=5$ we'd have $M_{2100} \equiv 5+5\equiv 3$, $M_{2200}\equiv 3+5\equiv 1\pmod 7$. And $M_{2300}\equiv 1+5\equiv 6\pmod 7$ but, $M_{2400}\equiv 6+6\equiv 5$. And we repeat.... (Very nice, the Gregorian calendar based make every four hundred years has a multiple of $7$ days so we always repeat.

So if $M_{xx00} = c_y = 5, 3,1,6$ for leap, leap +100, leap + 200, leap + 300$

We get the formula.

Month $d$, $yyxx$ where $yyxx = 400*k + 100*y + xx$ then $D = d + c_m + c_y + xx+\lceil \frac {xx}4\rceil\pmod 7$


Dec 31, 1299 was on a thursday$= 4$.

So Jan k, 1300 would be $k$ days later. So that would be $k +4$. But there are only seven days a week so they repeat every $7$ days so we will use $k+ 4\pmod 7$ to figure out the day of the week.

So for any date we will estimate the numbers of days since Dec 31, 1299 and take the remainder divided by $7$. To get that Jan k, 1300 is on the date $k +4\pmod 7$ we have an offset of $4$. If we let Jan account for offset of $1$ and $1300$ account for offset of $3$ the formula works so far for the Dates Jan 1-31, 1300. $D = d + c_m +c_y \pmod 7$ where $d=1-31$ and $c_m =1$ (completely arbitrary) and $c_y=3$ (ditto).

Now Feb m, 1300 would be $31 + m + $ days later. But $31\equiv 3 \pmod 7$ so instead off offsetting by $4$ we offset but $4+ 3 \equiv 0\pmod 7$. So if the offset code, $c_m$ of Jan was $1$, and Jan has $31 \equiv 3 \pmod 7$ days, then the offset code, $c_m$ for February must be $1+3\equiv 4\pmod 7$.

And so on for all the months. Feb has $28\equiv 0 \pmod 7$ days so the $c_m$ for March is $4+0=0$. And March has $31\equiv 3 \pmod 7$ days so the offset for april is $4 + 3 \equiv 0 \pmod 7$. And so on.

So in this way we can figure out all the days from Jan 1, 1300 to Dec 31 1300.

Okay, now a year has $365=52*7 + 1\equiv 1 \pmod 7$. So any day of a date in 1301 will be $1$ day latter than the same date in $1300$. And any day of a date in 130$j$ will be $j$ days latter than the same date in $1300$.

But every fourth year is a leap year and that addes an extra day every four years.

So that tells us how to calculate any date in the $1300$. Now a century has some many days $\pmod 7$. So that is way we have the century code, $c_y$. Some centuries have leap years on $xx$00 and others don't so the code takes that into account.

And that's that.


Although.... I don't think those values are right. The ceiling rather than floor can only work if $xx00$ belongs to the century before (which properly it does) And I did calculations and the century offsets didn't agree with my calculations. (But it was late and I didn't do it too carefully, and maybe I was assuming all centuries began with 00 and maybe they do work for centuries begining on 01.)

  • $\begingroup$ Your century code were not matching with the table. So I edited it a bit . Is it right? BTW Thanks, I really like your new approach. $\endgroup$
    – Wolgwang
    Nov 6, 2020 at 17:11
  • $\begingroup$ I thought for a while the codes were wrong but as non leap centurys add an extra day to $c_{jan}$ they are actually offsetting from Dec 30, not Dec 31. .... Maybe I'll work on a third explanation but... enough is enough. $\endgroup$
    – fleablood
    Nov 6, 2020 at 17:21
  • $\begingroup$ I am satisfied with your answers. I don't need any more explanation. Thanks :-) $\endgroup$
    – Wolgwang
    Nov 6, 2020 at 17:24
  • $\begingroup$ The teacher's formula is incorrect. It should be floor rather than ceiling. I checked a couple different spans of multiple years day by day with a spreadsheet and an online calendar; the formula with floor is correct always, but the formula with ceil is correct only in years divisible by 4 and is off by 1 in every other year. $\endgroup$
    – David K
    Mar 7, 2021 at 17:26
  • $\begingroup$ @DavidK Oops! That was a typo. Thank you for bringing that to my notice. I have fixed it now :-) $\endgroup$
    – Wolgwang
    Mar 8, 2021 at 17:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .