How to find day of a date

Solution 1:

Here is a method to convert between the Gregorian Calendar and the Julian Day Number.

Suppose the year, month, and date are given by $(Y,M,D)$ where January and February are included in the previous year, and March is month $0$ of its year. Thus, January 1, 2000 would be $(1999,10,1)$. Then the Julian Day Number that starts at noon GMT on that day would be $$ \text{JDN} = 365Y + \left\lfloor\frac Y4\right\rfloor - \left\lfloor\frac Y{100}\right\rfloor + \left\lfloor\frac Y{400}\right\rfloor + \left\lfloor\frac{153M+2}5\right\rfloor + D + 1721119 $$ To get the day of the week, $\text{DOW}$, use $\text{JDN}+1 \equiv \text{DOW} \pmod7$ where $$ \begin{align} 0 &= \text{Sunday}\\ 1 &= \text{Monday}\\ 2 &= \text{Tuesday}\\ 3 &= \text{Wednesday}\\ 4 &= \text{Thursday}\\ 5 &= \text{Friday}\\ 6 &= \text{Saturday} \end{align} $$ The inversion of this process is a bit more complicated. To convert from $\text{JDN}$ to $(Y,M,D)$, use the following: $$ \begin{align} Q_1 &= \left\lfloor\dfrac{\text{JDN}-1721120}{146097}\right\rfloor\\ R_1 &= (\text{JDN}-1721120) - 146097 Q_1\\ Q_2 &= \min\left(\left\lfloor\frac{R_1}{36524}\right\rfloor,3\right)\\ R_2 &= R_1 - 36524 Q_2\\ Q_3 &= \left\lfloor\frac{R_2}{1461}\right\rfloor\\ R_3 &= R_2 - 1461 Q_3\\ Q_4 &= \min\left(\left\lfloor\frac{R_3}{365}\right\rfloor,3\right)\\ R_4 &= R_3 - 365 Q_4\\[18pt] Y &= 400 Q_1 +100 Q_2 + 4 Q_3 + Q_4\\[6pt] M &= \left\lfloor\frac{5R_4+2}{153}\right\rfloor\\ D &= R_4 - \left\lfloor\frac{153M+2}5\right\rfloor + 1 \end{align} $$

Solution 2:

Compute the number of days, modulo 7. Add the result to your present day.

For instance, today is Thursday, August 22, 2013.

August 23, 2014 is 366 days away.

$$366 \equiv 2 \bmod 7,$$

so August 23, 2014 is a Saturday.

Computing the number of days between dates is tedious, but not difficult.