How to find the day for a given date ?

Many are very much interested to find out the day in which they are born (birth "day"), most simple solution is open the date and time properties (by double clicking the clock in the down right corner in your desktop) and find the day corresponding to the date you required. However we can do that only for years 1980 or above in win XP. Or you can find some online programs/javascript that will do the job for you. This post will explain you the logic on how to do it manually.

Before knowing how to find out, we need to know some info:
* The no of days in each month in a year is 31, 28(29), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
* Now the odd days in each month in a year 3, 0(1), 3, 2, 3, 2, 3, 3, 2, 3, 2, 3
(odd days are obtained by finding the remainder when the no of days are divided by 7)
* % - gives remainder in a division operation
* Leap year: A year is said to be Leap year if it contains 29 days in February.

How to find whether a year is leap year or not ?
1) We get a leap year if that year is divisible by 4 exactly (eg., 1996 % 4 = 0 --> remainder)
2) Years divisible by 100 and not by 400 is not a leap year
eg 1) 1900 % 100 = 0 , not divisible by 400, hence 1900 is not a leap year. Similarly 2100,2200 are all not leap years.
eg 2) 2000 % 100 = 0 , divisible by 400, hence 2000 is a leap year. Similarly 2400, 2800 etc.

Now let us take an example:
We assume that we need to find the day of Aug 15, 1947 (India's Independence Day).

Step 1: Find leap year or not.
Using the above said conditions, find whether your year is leap year or not. To know whether a number is divisible by 4, you can see here
* 1947 is not a leap year as it is not divisible by 4

Step 2: Find out total odd days on months.
Method 1: Add all the days in the months before your month (that is august) and the date (that is 15) and find the remainder when the sum is divided by 7
* 31 + 28 (since, not a leap year) +31+30+31+30+31+ 15 = 227
* 227%7 = 3

Method 2: If adding like above is difficult, add all the odd days the months before august and add 15 % 7 = 1 to it. And then find the remainder when the sum is divided by 7.
* 3 +0(since not leap year) +3+2+3+2+3+1 = 17
* 17%7 = 3

-------------------------------------------------------------------------------------------------------------------
Consider 1601 - 1700
Every year we have one odd day (meaning 365 % 7 = 1)
Every leap year have two odd day (meaning 366 % 7 = 2)
In 100 years (say 1601 - 1700) we have 24 leap years, 76 normal years.
That implies no of odd days in every 100 year = (2 x 24 + 1 x 76 ) % 7 = 124 % 7 = 5

so far 1601 - 1700 - 5 odd days
for 1701-1800 - 5 odd days
for 1801-1900 - 5 odd days
for 1901-2000 - 5 + 1 odd days
Since 2000 is a leap year where as 1700 and others are not, we have added 1 in the last statement.

So far a set of 400, we have (5+5+5+6 )%7 = 21 % 7 = 0 odd days

This implies, if 1-1-1601 is some day, then 1-1-2001 is also the same day, as the diff between them is 400.

So we can reduce multiples of 400 from the year we have.
that is 1947-1600= 347
-------------------------------------------------------------------------------------------------------------------

Step 3: Find out the total odd days on year.
Step 3(i): (only if greater than or equal to 100 in the above calculation)

In 347 we have, 3 hundreds

Therefore we have
(no of odd days per hundred x no of hundreds) % 7 = (5 x 3) % 7 = 15 % 7 = 1

Now we can reduce multiple of 100 from the year we have.
347-300=47

Step 3 (ii) : Only if year greater than 1 in last calculation
We have already found the odd days in the 1947th year in step 2
Excluding the 47th year, there are 11 leap years and 35 normal years from 1901-1946
so (11x2 + 35x1) % 7 = 57 % 7 = 1

Step 4: (step 2 + step 3(i) + step 3(ii)) % 7
(3 + 1 + 1 ) % 7 = 5 % 7

Jan 1, 2001 is a Monday, depending on odd day, we have
1 is Monday
2 is Tuesday
3 is Wednesday
4 is Thursday
5 is Friday
6 is Saturday
0 or 7 is Sunday

so 5 is Friday , which is the day of Aug 15th, 1947.

What we have obtained is relative to 1-1-2001. If you are going to write a program using a programming language, this will be helpful to you to know the logic behind the program.

Note: In ancient time due to the difference in the mean real day and mean solar day, people have added an extra day every 4 years to compensate for it (which lead to Feb 29th). However they later found that in 1582 that, there is still some non-synchronization and this lead to Gregorian calendar which we follow today commonly. In Gregorian Calendar the conditions, as stated in how to find a leap year, are followed to make the necessary corrections due to the difference in the mean real day and mean solar day.

2 comments:

Anonymous said...

in last step 3+1+1 =5 but it written as 4 and concluded 4leads to thursday and said the day of the year.
Please clarify my doubt.
Thank you.

Trix said...

Good find. Corrected !!

Post a Comment