Post Reply 
days-between-dates Solver equation for 17b
10-06-2018, 03:27 PM (This post was last modified: 10-06-2018 08:37 PM by Albert Chan.)
Post: #6
RE: days-between-dates Solver equation for 17b
Trivia: New Year's Day for year 400k are all Saturday
Prove:
Let y = 400k, setup so that day(1/1/1) = 1, a Monday

day(12/31/y) = 365*y + y/4 - y/100 + y/400 = 146097 y / 400 = 146097 k
Since 146097 % 7 = 0, day(12/31/y) % 7 = 0, a Sunday

Travel back time 365 days (y is leap year), 1/1/y is -365 % 7 = 6, a Saturday Smile
---

With above trivia, we can extend day range furthur:

day(m/d/y) = day(m/d/(y%400)) + 146097*floor(y/400)

Or, if no overflow issue, even simpler (without divide or modulo 400):

day(m/d/y) = day(m/d/(y%10000)) + 3652425*floor(y/10000)

For days-of-week calculation, last term can be dropped (it is divisible by 7).
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: days-between-dates Solver equation for 17b - Albert Chan - 10-06-2018 03:27 PM



User(s) browsing this thread: 2 Guest(s)