How to find the week day of (any) given date?

718 Views Asked by At

How to find the week day of any given date?

Say we need to know in which week-day was June $25,2019$?

1

There are 1 best solutions below

5
On BEST ANSWER

To determine the week-day of a given date, we need to:

  • find out whether the given year is "common" or "leap".

  • know $\mod(a,b)$.

  • know $\left \lfloor a \right \rfloor$.


To find out whether the given year is "common" or "leap", we can use the following chart:

enter image description here

$\mod(a,b)$ means the remainder when dividing $a$ by $b$. For example, when we divide $17$ by $3$, we get $5$ and the remainder is $2$. Therefore, $\mod(17,3)=2$.

For convince, $\mod(a,100)=$ the number formed by the last two digits of $a$. For example, $\mod(13527,100)=27$.


$\left \lfloor a \right \rfloor$ means the nearst integer less than or equal to $a$. For examples,

$\left \lfloor 6.97 \right \rfloor=6$,$\left \lfloor -2.8 \right \rfloor=-3,\left \lfloor \frac{20}{4} \right \rfloor=5$.


Suppose that the given date is of the form: MONTH $d, y$

We have to calculate the following:

  • $A=\mod(y,100)$

  • $B=\left \lfloor \frac{A}{4} \right \rfloor$

  • $C=\frac{y-A}{100}$

  • $D = d$ which is the given date.

  • $E =\left \lfloor \frac{C}{4} \right \rfloor$

  • $F=0,3,2,5,0,3,5,1,4,6,2,$ or $4$ depending on the given month (Jan, Feb, March, ..., or Dec) respectively.

  • $G=\left\{\begin{matrix} 0 & \text{if the month is not Jan nor Feb}\\ 1 & \text{for Jan or Feb in a common year}\\ 2 & \text{for Jan or Feb in a leap year} \end{matrix}\right.$

  • $H=\mod(A+B-2C+D+E+F-G,7)$

  • The week-day depends on the $H$ value, $0$ for Sunday, $1$ for Monday, $2$ for Tuesday, $3$ for Wednesday, $4$ for Thursday, $5$ for Friday, and $6$ for Saturday.


Consider the example, June $25,2019$

Since $2019$ is not divisible by $4$, then $2019$ is a common year.

$A=\mod(2019,100)=19$

$B= \left \lfloor \frac{19}{4} \right \rfloor=4$

$C=\frac{2019-19}{100}=20$

$D= 25$ as given.

$E= \left \lfloor \frac{20}{4} \right \rfloor=5$

$F=3$ for June.

$G=0$ since the given month is neither Jan nor Feb.

$H=\mod(19+4-2\times20+25+5+3-0,7)=\mod(16,7)=2=$ Tuesday.


I noticed that many people ask about this. I posted this way because I think it is the simplest way for any given date , whatever the given century.

There are some simpler ways but for years between 2000 and 2099 only.

So it is a general way.

If you know any simpler way than this, please leave a comment or just post it as an answer, THANKS!.

This may be a useful page for you: https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week