Formula to find the day of any date in Gregorian calendar derivation.

calendar-computationsmodular arithmetic

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

Expression:

$$ \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.

And

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.

Thanks


Note:

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

Best Answer

NEW ANSWER!

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.)

Related Question