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