i get a date input from the user..in this case i need to determine if the year the user entered is a leap year or not …and after the user has entered the entire date i.e the month date and year…i need to check if the date is in fact valid if yes need to determine the day for that particular date.. can some one tell me how this could be done..
Share
2.6. What day of the week was 2 August 1953? -------------------------------------------- To calculate the day on which a particular date falls, the following algorithm may be used (the divisions are integer divisions, in which remainders are discarded): a = (14 - month) / 12 y = year - a m = month + 12*a - 2 For Julian calendar: d = (5 + day + y + y/4 + (31*m)/12) mod 7 For Gregorian calendar: d = (day + y + y/4 - y/100 + y/400 + (31*m)/12) mod 7 The value of d is 0 for a Sunday, 1 for a Monday, 2 for a Tuesday, etc. Example: On what day of the week was the author born? My birthday is 2 August 1953 (Gregorian, of course). a = (14 - 8) / 12 = 0 y = 1953 - 0 = 1953 m = 8 + 12*0 - 2 = 6 d = (2 + 1953 + 1953/4 - 1953/100 + 1953/400 + (31*6)/12) mod 7 = (2 + 1953 + 488 - 19 + 4 + 15 ) mod 7 = 2443 mod 7 = 0 I was born on a Sunday.Read the Calendar FAQ for more information.