Vishal Suthar
Vishal Suthar

Reputation: 17193

Algorithm for Calendar Calculation

One of the interview question..

If

1st january 2006 --> Sunday

Then

1st january 2010 --> ???

Upvotes: 0

Views: 202

Answers (2)

Ranjit Singh
Ranjit Singh

Reputation: 3735

add 1 day for each non-leap year and 2 days for each leap year whatever comes that value mod 7.And finally add that amount of days with the given day. for eg.

2007=1 day

2008=2 days

2009=1 day

2010=1 day

so total 5 days and 5 % 7=5 Add 5 days in sunday,so you will get Friday

Upvotes: 2

Marcus
Marcus

Reputation: 6839

Year 2006 is not a leap year, it has 365 days.

Year 2007 has 365 days.

Year 2008 is a leap year, it has 366 days.

Year 2009, 365 days.

So there're 365+365+366+365==1461 days different of the two dates.

One week has 7 days, and 1461 mod 7 is 5, 5 days after Sunday is Friday.

So the answer is Friday.

Upvotes: 0

Related Questions