Post Reply 
(HP-65) Date Functions
01-04-2020, 01:03 PM (This post was last modified: 01-14-2020 04:41 PM by Albert Chan.)
Post: #4
RE: (HP-65) Date Functions
(01-03-2020 04:11 PM)Dave Britten Wrote:  Calculations are accurate for dates between Mar. 1, 1900 through Feb. 28, 2100. Some limited calculations outside this range can be done accurately, but the program incorrectly treats all years divisible by 100 as leap years, whereas years divisible by 100 but not divisible by 400 are not leap years. Day-of-week calculations will be incorrect outside the supported date range.

A simple trick to manually make it work for all dates:

Gregorian calendar have a period of 400 years, (97 leap years → 146097 days/(4 century))
For 22nd, 23rd, 24th century, we have 24 leap years / century →  36524 days/century

Example: day number of Jan 2, 3456

3456 = 2056 + 3*400 + 200 → day(Jan 2, 3456) = day(Jan 2, 2056) + 3*146097 + 2*36524

Example: day number of July 4, 1776

1776 = 1976 - 200              → day(July 4, 1776) = day(July 4, 1976) - 2*36524

Example: day number of Jan 1, 1900

We could "move up" 1 century to 2000, but then we need to check the months and the days too.
A simpler way is shoot high, and adjust between Feb 29, 2000 to Feb 28, 2100.

1900 = 2100 - 400 + 200     → day(Jan 1, 1900) = day(Jan 1, 2100) - 146097 + 2*36524

Update: shoot low and adjust between Mar 1, 1900 to Feb 28, 2000 works too.
→ day(July 4, 1776) = day(July 4, 1976) - 2*36524
→ day(Jan 1, 1900) = day(Jan 1, 2000) - 36524

Combine both approaches, using full valid date, Mar. 1, 1900 through Feb. 28, 2100

day(date) = day(closest centuries shifted valid date) - IP(36524.25 * shifted centuries)

→ day(Jan 2, 3456) = day(Jan 2, 2056) - IP(36524.25 * (20-34)) = day(Jan 2, 2056) + 511339
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(HP-65) Date Functions - Dave Britten - 01-03-2020, 04:11 PM
RE: (HP-65) Date Functions - Don Shepherd - 01-03-2020, 04:23 PM
RE: (HP-65) Date Functions - Dave Britten - 01-03-2020, 04:46 PM
RE: (HP-65) Date Functions - Albert Chan - 01-04-2020 01:03 PM



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