Post Reply 
Deltadays and date functions.
05-12-2017, 08:04 PM
Post: #21
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.

Now that various aspects of the algorithm have been discussed, here are three complete program listings for the 15C. Enter day [ENTER] month [ENTER] year, call [D] and get a serial number that allows to calculate the number of days between two dates by simple subtraction.

1. Compact version (33 steps), works for dates between 1 Mar 1900 and 28 Feb 2100.
If you want the Julian day number, add 1720982 to the result.

Code:
001  LBL D
002  STO 0
003  R↓
004  3
005  x≤y?
006  GTO 0
007  +
008  9
009  +
010  1
011  STO-0
012  LBL 0
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

2. Standard version (44 steps) that works down to the first day of the Gregorian calendar (15 Oct 1582).
If you want the Julian day number, add 1720997 to the result.

Code:
001  LBL D
002  STO 0
003  R↓
004  3
005  x≤y?
006  GTO 0
007  +
008  9
009  +
010  1
011  STO-0
012  LBL 0
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  RCL 0
034  EEX
035  2
036  /
037  INT
038  -
039  LSTx
040  4
041  /
042  INT
043  +
044  RTN

3. Deluxe version (64 steps) with automatic switch between Julian and Gregorian calendar (4↔15 Oct 1582). Works down to 1 Mar 0000, returns Julian day number.

Code:
001  LBL D
002  STO 0
003  R↓
004  3
005  x≤y?
006  GTO 0
007  +
008  9
009  +
010  1
011  STO-0
012  LBL 0
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  5
034  7
035  8
036  1
037  6
038  5
039  -
040  x≤0? (TEST 4)
041  GTO 1
042  RCL 0
043  EEX
044  2
045  /
046  INT
047  -
048  LSTx
049  4
050  /
051  INT
052  +
053  2
054  +
055  LBL 1
056  2
057  2
058  9
059  9
060  1
061  6
062  0
063  +
064  RTN

In all versions one stack level is preserved so that date differences can be easily calculated with two successive runs of the program.

28 [ENTER] 2 [ENTER] 2100  f[D]  →  2488128 (assuming deluxe version)
  1 [ENTER] 3 [ENTER] 1900  f[D]  →  2415080 (assuming deluxe version)
[–]  →  73048 days

Dieter
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: 2 Guest(s)