Post Reply 
Year(s) Month(s) Day(s) between 2 dates
10-22-2015, 04:00 PM
Post: #16
RE: Year(s) Month(s) Day(s) between 2 dates
The program from Dieter is extremely well done. However it’s still possible to squeeze out a few steps Smile

Here is a slightly modified version using local registers instead of global ones and without the need for flag 00:

Code:
01 LBL"YMD"   ; stack: date2, date1
02 LocR 005   ; allocate local registers R.00 to R.04
03 STO.02     ; store date2 in R.02
04 DATE->     ; stack: d2, m2, y2, date1
05 X<>Y       ; stack: m2, d2, y2, date1
06 STO.03     ; store m2 in R.03
07 X<>Z       ; stack: y2, d2, m2, date1
08 STO.04     ; store y2 in R.03
09 <>TYZX     ; stack: date1, d2, m2, y2
10 STO.01     ; Store date1 in R.01
11 DAY        ; stack: d1, d2, m2, y2
12  -         ; stack: d2-d1, m2, y2 – LastX: d1
13 x≥0?       ; d2 ≥ d1?
14 SKIP 011   ; no adjustment required, goto step 26
15 DEC.03     ; adjust m2 in R.03
16 DROP       ; stack: m2, y2 – LastX: d1
17 DSZ X      ; month before m2
18 SKIP 003   ; is it > 0, i.e. Jan...Nov? Then continue
19 DROP
20 #012       ; if not, month is December
21 DEC Y      ; of previous year
22 RCL L      ; now stack holds d1, m2-1, year of m2-1
23 ->DATE     ; generate new date = d1 in month before m2
24 RCL.02
25 ΔDAYS      ; days between date2 and d1 in month before date2
26 SDR 004    ; move days to 0,00dd
27 RCL.01     ; recall date1
28 DATE->     ; stack: d1, m1, y1, 0,00dd
29 DROP       ; stack: m1, y1, 0,00dd
30 cSTO-.03   ; R.03: m2-m1, R.04: y2-y1
31 cDROP      ; stack: 0,00dd
32 RCL.03     ; stack: m2-m1, 0,00dd
33 x≥0?       ; stack: m2-m1, 0,00dd
34 SKIP 003
35 DEC.04     ; adjust y2-y1 in R.04 if m2-m1 negative
36 #012       ; add back 12 months
37  +         ; stack: mm, 0,00dd 
38 SDR 002    ; move months to 0,mm
39  +         ; add days to get 0,mmdd
40 RCL+.04    ; recall and add y2-y1 
41 END        ; return y,mmdd
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Year(s) Month(s) Day(s) between 2 dates - Didier Lachieze - 10-22-2015 04:00 PM



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