Post Reply 
days-between-dates Solver equation for 17b
10-07-2018, 07:14 AM (This post was last modified: 10-07-2018 08:36 AM by Dieter.)
Post: #10
RE: days-between-dates Solver equation for 17b
(10-06-2018 11:57 PM)brickviking Wrote:  Speaking of going back in time, do these algorithms take any notice of the 11 days lost in 1753-ish? (varies between countries from 1753 to as late as 1923).

The formula calculates the day number based on the rules of the Gregorian calendar. So it works for dates since 15 October 1582 (which followed directly after 4 October). For earlier dates (i.e. until 4 October 1582) a different formula (for the Julian calendar) has to be applied.

If you want a different date for the switch between Julian and Gregorian calendar, for instance the one in 1752 when the British colonies (including the US) adopted the new system, the current formula will only work for dates since then. For earlier dates the Julian formula has to be used, just as mentioned above for dates until 4 October 1582.

In simple words: there are two formulas, one for the rules according to the Julian calendar and another one for those of the Gregorian calendar. It's you choice when to switch from one to the other. The earliest possible date is 4...15 Oct 1582 because before that the new Gregorian system was not yet defined.

Further reading (with both Julian and Gregorian formulas): Wikibooks (in German).
Note: the Julian Day Number (JDN) and the value g() calculated by the formula in this thread differ by a constant offset of 1721120 (which is not required for date differences). Also the JDNs in the Wikibook formula may have a fractional part that represents the time, here 0,5 means midnight.

Edit: for simple date differences only the g() formula is required. This turns a Gregorian date into a day number. For the Julian calendar the equivalent function j() is:

Code:
function j(y,m,d)
m = (m + 9) % 12
y = y - m/10
return 365*y + y/4 + (m*306 + 5)/10 + d - 3

As usual, all "/" are integer divisions.

Check:
g(1582,10,15) = 578041
j (1582,10, 4 ) = 578040

After y has been adjusted, the difference between both calendar systems is  2 – y/100 + y/400 days. Or y/100 – y/400 – 2 days, if you prefer positive numbers.
That's the 11 days for a calendar switch in 1752, or 13 days today.

Dieter
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 - Dieter - 10-07-2018 07:14 AM



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