25 August 2010

How to get DAY name from the given DATE ?

suppose you have such a question that on 27-may-1991 what was the DAY?
so... Here is the math trick to get the DAY name from the DATE.

Remember this 2 table
=> MONTH CODE
jan  =1
feb  =4
mar=4
apr =0
may=2
jun  =5
jul   =0
aug=3
sep=6
oct  =1
nov =4
dec=6
(if LEAP YEAR then jan=0, feb=3)

=> DAY CODE (IF year <= 2000)
sun  =1
mon=2
tue  =3
wed=4
thu =5
fri   =6
sat =0

=> DAY CODE (IF year >= 2000)
sun  =0
mon=1
tue  =2
wed=3
thu =4
fri   =5
sat =6

 

step.1
sum of DAY + MONTH CODE + last 2 digit of YEAR + int(1/4th of Last 2 digit of YEAR)

step.2
divide SUM by 7

step.3
now compare REMINDER of STEP.2 with DAY CODE
its your DAY of that DATE


example
if the DATE is 27-may-1991 then find the DAY
step.1
27 + 2(month code)+ 91 + 22
(here 1/4th of 1991 is 22.75 but truncate fraction part so only 22 will be considered)
so, SUM=142
step.2
=142/7
so, REMINDER = 2
step.3
see REMINDER in table of DAY CODE
so... 2= MONDAY is my b'day
so... that we can say that... on DATE 27-may-1991 the day was Monday.

Try this l0g!c........

No comments :

Post a Comment

Popular Posts