Post Reply 
Deltadays and date functions.
05-10-2017, 05:01 PM (This post was last modified: 05-10-2017 09:17 PM by Dieter.)
Post: #8
RE: Deltadays and date functions.
(05-10-2017 01:28 PM)Vtile Wrote:  I have been in seach of simple algorithm to calculate dDays between two dates.
The JDN method is too heavy to my use (DM15/HP15C)

What? Heavy? A program that works correctly for any valid Gregorian date can be done in less than 80 steps. Take a look at the old HP41 library on this website.

(05-10-2017 01:28 PM)Vtile Wrote:  ...as it needs to be accurate only between about 100 year time window.

In this case things can be simplified a bit. For dates between (and including) 1 Mar 1900 and 28 Feb 2100 every fourth year is a leap year (that's because 2000 is one). This allows to use a simpler formula.

(05-10-2017 01:28 PM)Vtile Wrote:  I did found one that suits my use at: https://groups.google.com/forum/#!topic/...c9rcvY7d2s

Hmmm... looks like a few things have been mixed up there. See below.

(05-10-2017 01:28 PM)Vtile Wrote:  Now interesting enough I did put 3 different methods to the excel worksheet to compare them simultaneusly.. If I take DDays from 28.2.1900 and 28.2.2100 I get results:

Excel (365): 73050
JDN-JDN^^: 73049
HP50g DDAYS: 73049
SIMPLE DDAYS**: 73050
WAlpha: 73049 ( https://www.wolframalpha.com/input/?i=DA...+28.2.2100 ) PS. As late though

So which ones are correct?

73049 is correct. As usual, Excel cannot be trusted under all circumstances. The date functions only work for a certain range, so you better write your own.

(05-10-2017 01:28 PM)Vtile Wrote:  ** From mailinglist discussion
Y <- start year
M <- start month
D <- start day
Y <- Y-1
M <- M+13
X <- int(365.25*Y)+int(30.6*M)+D

As already mentioned, some things get mixed up here. For instance an Y and M adjustment has to be applied only for Jan and Feb, and not for all months. For dates between 1 Mar 1900 and 28 Feb 2100 you may use the following method:

Code:
Count Jan and Feb as month 13 and 14 of the previous year:
IF M<3 THEN M=M+12 and Y=Y-1

Then calculate N = INT(Y*365,25) + INT((M+1)*30,6) + D

Δdays = N(date2) - N(date1)

A 15C program can be done in a few minutes:

Code:
001 LBL D
002 STO 0
003 R↓
004 3
005 x<=y?
006 GTO 00
007 +
008 9
009 +
010 1
011 STO- 0
012 LBL 00
013 R↓
014 1
015 +
016 3
017 0
018 ,
019 6
020 x
021 INT
022 +
023 RCL 0
024 3
025 6
026 5
027 ,
028 2
029 5
030 x
031 INT
032 +
033 RTN

This way day [ENTER] month [ENTER] year f[D] returns N(date).
Since the uppermost stack register is preserved, the number of days between two dates can be determined easily:

28 [ENTER] 2 [ENTER] 2100 f[D] => 767146
  1 [ENTER] 3 [ENTER] 1900 f[D] => 694098
  [–] => 73048

Dieter

Edit: changed program slightly (omitted DSE 0 and RCLx 0) so that it can also be used with most traditional RPN HPs.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Deltadays and date functions. - Vtile - 05-10-2017, 01:28 PM
RE: Deltadays and date functions. - Vtile - 05-10-2017, 01:50 PM
RE: Deltadays and date functions. - Vtile - 05-10-2017, 03:02 PM
RE: Deltadays and date functions. - Vtile - 05-10-2017, 07:55 PM
RE: Deltadays and date functions. - Dieter - 05-10-2017, 08:30 PM
RE: Deltadays and date functions. - KeithB - 05-10-2017, 04:30 PM
RE: Deltadays and date functions. - Dieter - 05-10-2017 05:01 PM
RE: Deltadays and date functions. - Vtile - 05-10-2017, 07:16 PM
RE: Deltadays and date functions. - Dieter - 05-10-2017, 08:17 PM
RE: Deltadays and date functions. - Vtile - 05-10-2017, 05:12 PM
RE: Deltadays and date functions. - Dieter - 05-10-2017, 06:17 PM
RE: Deltadays and date functions. - Vtile - 05-11-2017, 11:33 AM
RE: Deltadays and date functions. - Dieter - 05-11-2017, 05:03 PM
RE: Deltadays and date functions. - Vtile - 05-11-2017, 04:17 PM
RE: Deltadays and date functions. - Dieter - 05-12-2017, 08:04 PM
RE: Deltadays and date functions. - Dieter - 05-13-2017, 01:32 PM
RE: Deltadays and date functions. - Dieter - 05-14-2017, 05:21 PM
RE: Deltadays and date functions. - Vtile - 05-12-2017, 11:58 PM
RE: Deltadays and date functions. - Dieter - 05-13-2017, 01:33 PM
RE: Deltadays and date functions. - Vtile - 05-13-2017, 07:15 PM
RE: Deltadays and date functions. - Dieter - 05-13-2017, 08:57 PM
RE: Deltadays and date functions. - Vtile - 05-13-2017, 10:30 PM



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