UMER’S Algorithmfor date to day conversion

Suppose we have a date D-M-Y and we want to determine the day of week on which that date falls. We can do this in three simple steps:

IMPORTANT TERM: Before starting we have to learn an important term, the mod operator. The mod operator returns the remainder after division of two numbers. For example, (13 mod 5) = 3 because when we divide 13 by 5, the remainder is 3.

Step 1:
The first step is to determine the values of some important terms:

  1.  Y = The year found from the date. For example, in 14th August 1947, Y=1947.

  2.  D = Date of the month. For example, in 14th August 1947, D= 14.

  3.  L.Y = (Y – (Y mod 4) ) ÷ 4

  4.  M.C = It is found according to the month from the table below:


Month
M.C
January
0
February
3
March
3
April
6
May
1
June
4
July
6
August
2
September
5
October
0
November
3
December
5

  5.     n and c are Boolean variables (Their value is either 0 or 1)

·        n = 1 if  (Y mod 4) = 0 , otherwise n = 0.

·        c = 1 if the month is January or February otherwise c= 0.

Step 2:

The second step is to compute the DayCodeusing a formula:

DayCode =(5+Y +D +L.Y +M.Cnc)mod 7

Step 3:

The final step is to determine the Day using DayCode from the table below:


DayCode
Day
0
Sunday
1
Monday
2
Tuesday
3
Wednesday
4
Thursday
5
Friday
6
Saturday








It is always good to share.