Post Reply 
Year(s) Month(s) Day(s) between 2 dates
10-27-2015, 03:06 PM
Post: #26
RE: Year(s) Month(s) Day(s) between 2 dates
Hi,

I've now entered both programs from Dieter and Didier (each in the last updated version), and there must be something wrong with the listings, because both programs don't work correctly!

Look at the results for the 3 dates that have been mentioned in this thread:
Code:

18.071978 to 19.102015 --> 36.1431 instead of 37.0301
14.051643 to 01.091715 --> 71.1518 instead of 72.0318
23.021951 to 05.091999 --> 47.1813 instead of 48.0613
Not even the most simple dates work, where every number in date2 is higher than in date1, although in this case you could even just subtract the 2 dates:
Quote:03.052000 to 10.102015 --> 14.1637 (16 months?, 37 days?)
And for some special dates the results are complete nonsense:
Quote:01.012000 to 01.022000 --> -0.87
31.012015 to 01.032015 --> Domain Error
31.012015 to 01.042015 --> -0.8599

And now about the problem of 2 different results for Didier's example (23 Feb. 1951 to 5 Sept. 1999):
I definitely agree with Gérard that the 'correct' result is 48y/6m/10d and NOT 48y/6m/13d!

You can't move forward to 23 Aug 1999, at least NOT for all cases - try your method with the following 2 dates (in any year YYYY):
31 Jan. YYYY to 5 March YYYY
You can't move forward to 31 Feb., because Feb. simply doesn't have 31 days!
(same problem with 30 or 29 Jan, or if the 2nd month is May/July/Oct/Dec)

So in fact Gérard's method is correct, unless you want to make a lot of differences between all kinds of months.

In short words: (for d1.m1yyy1 to d2.m2yyy2)
If d2<d1, then you have to add the remaining days in m1 and the days d2, and change the first date to the 1st day of the following month.

Here's my own (really working! Wink) version, which uses exactly the method I've described above - you only must take care that the result is also in the same format DD.MMYYYY as the the input dates (therefore the name DMY)!
I've made it this way, because
1) IMO it's more consistent if the input and output have the same format, and
2) everything can be done on the 4-level stack (no extra registers needed), so
3) the program is much smaller (only 29 steps!)

Quote:0001 LBL'DMY'
0002 [<->] YXYX
0003 [cmplx]IP
0004 x[<=]? Y
0005 SKIP 011
0006 [<->] ZZTT
0007 FP
0008 INC X
0009 # 031
0010 DAYS+
0011 FP
0012 INC X
0013 STO Z
0014 [DELTA]DAYS
0015 STO+ Z
0016 ENTER[^]
0017 [<->] ZTZT
0018 [cmplx]FP
0019 x[<=]? Y
0020 SKIP 006
0021 DROP
0022 # 012
0023 SDL 004
0024 DEC X
0025 SDR 006
0026 STO+ T
0027 [cmplx]DROP
0028 -
0029 END

Franz
Visit this user's website 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 - fhub - 10-27-2015 03:06 PM



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