Flipkart Deals

Flipkart.com

March 11, 2011

Calculate the day of any date

Do you want to know How to calculate the day of any given date off hand?

Then read on..

For any given date, there is a simple workable formula to calculate the corresponding day. Since for most of the times we would work with dates in 20th and 21st century, So let me just limit myself to explain a simple formula that would work for these 200 years!


Method:
Given any date between 1900 to 2099, to calculate the corresponding day off the hand, we need to extract the following numbers.

Legend:
DD - day in the month
MM - month
CC - century
YY - year in the century
LY - no. of leap years past since beginning of century

Given Date: DD MM CCYY

LY - YY / 4 (last 2 digits of the year divided by 4) -> Quotient only

Y - YY mod 7 (last 2 digits of the year's remainder with 7)
L - LY mod 7 (no. of leap years in this century -> remainder with 7)
M - value in the string (033 614 625 035) corresponding to month
D - DD mod 7 (day in the month remainder with 7)
C - 0 if CC = 20th century; 6 if CC = 21st century
S - 6 if YY is leap & MM is Jan/Feb; else 0 (Special case for leap year)

Result = (Y+L+M+D+C+S) mod 7

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

So there you go.. you just got the day of the date!

Example:
Let us take a example - 26th Jan 1950 - India's Republic Day

Y = (50 mod 7) = 1
L = (12 mod 7) = 5 {LY = 50/4 = 12}
M = 0 ; from the number string (for jan it is 0)
D = (26 mod 7) = 5
C = 0 for 20th century (CC=19)
S = 0 (YY=50 not leap year)

Result = (1+5+0+5+0+0) mod 7 = 11 mod 7 = 4
Day = Thursday
So India's first Republic Day falls on a Thursday!

So we just saw how easily we can calculate the day of any date off hand..!
Now you can just go out, flaunt your skills and show that you are a genius!

As always I welcome your comments / questions.

No comments:

Post a Comment