Post Reply 
How many Years Months and Days ?
03-11-2015, 02:16 PM (This post was last modified: 03-11-2015 02:28 PM by Dieter.)
Post: #7
RE: How many Years Months and Days ?
(03-11-2015 08:46 AM)ggauny@live.fr Wrote:  You are really very fine, i very learn with you. I think you are teacher in maths or ingenior in informatic.

Far, far away from that. #-)

(03-11-2015 08:46 AM)ggauny@live.fr Wrote:  I remember in school the "chronological substraction" about same for hours, minutes and seconds.
...
We put only really finished years and months, days are days. If it is impossible to substract, i take on unity on the left and add in the new unity : - 1 year = +12 months, -1 month=30 days. Always 30days, never 28,29or 31, always 30 days.

If I understand this correctly, the method works as follows:

Code:
Let d1, m1, y1 (d2, m2, y2) represent the earlier (later) date.

Δd = d2-d1
if Δd<0 then
   Δd = Δd+30
   m2 = m2-1
Δm = m2-m1
if Δm<0 then
   Δm = Δm+12
   y2 = y2-1
Δy = y2-y1

On the HP41 series (and most other classic RPN HPs) this can be implemented easily.
The following code assumes two dates are entered in X and Y (earlier ENTER later) in dd.mmyyyy format.

Code:
01 LBL"YMD"
02 STO 02
03 INT
04 ST- 02
05 x<>y
06 STO 01
07 INT
08 ST- 01
09 -
10 100
11 ST* 01
12 ST* 02
13 RDN
14 x≠0?
15 x>0?
16 GTO 00
17 30
18 +
19 1
20 ST- 02
21 RDN
22 LBL 00
23 RCL 02
24 INT
25 ST- 02
26 RCL 01
27 INT
28 ST- 01
29 -
30 1E4
31 ST* 01
32 ST* 02
33 RDN
34 x≠0?
35 x>0?
36 GTO 00
37 12
38 +
39 1
40 ST- 02
41 RDN
42 LBL 00
43 RCL 02
44 RCL 01
45 -
46 END

72 Bytes

The result is returned in X (Δyears), Y (Δmonths) and Z (Δdays).

If you're not familiar with the tricks and tweaks of the olden days: the two consecutive tests (x≠0? x>0?) behave like a x≥0? test (which the '41 does not offer).

(03-11-2015 08:46 AM)ggauny@live.fr Wrote:  The chronologiqual substraction is the best and shorter to calculate Delta Y M D. No matter with leaps or not leaps etc.

It's a fast and concise method. Whether it's "the best" or not may be discussed – it's not quite exact. But not less so than the 30/360 method of the financial guys. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: How many Years Months and Days ? - Dieter - 03-11-2015 02:16 PM



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