Year(s) Month(s) Day(s) between 2 dates
|
10-19-2015, 09:33 AM
Post: #1
|
|||
|
|||
Year(s) Month(s) Day(s) between 2 dates
Hi, I've ported routine of mine from HP41cx to WP34s. Off course it's programmed "à la 41". I wonder if it's a way to load in one list the "31 STO 01 STO 03 etc.", I've check anywhere but I don't find. If it's possible, code will be less longer and speed up. All comments or ideas will be welcome. This routine is precise because we work with really numbers of days into month.
Do XEQ'YMD', ENTER DATE 1 RS (NOT ENTER !) DATE 2 RS (NOT ENTER !) Enjoy. Gérard. Code:
"Voilà". As an example : Well, if you use this routine crossing switch Julian Gregorian, keep in mind to minus result for 10 days : DATE1 = 3.101582 DATE2 = 18.101582 DISPLAY 15 days, but only 15-10 = 5 days ! (I hope my english is better since I've an english methode !) A good day for all. Gérard. Gérard. |
|||
10-19-2015, 10:01 AM
Post: #2
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
Why not use the built in function [Delta]DAYS for this?
- Pauli |
|||
10-19-2015, 10:50 AM
Post: #3
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
Bonjour Monsieur,
You are right but sometimes we need to know what means 35872 days. For example, my Mother is dead the 18/07/1978 (RIP), Delta days give me 13607 days, the routine give 37 years 3 months and 1 days. It is more speaking to mind I think. In Historical riserch, it is impossible to use a number of day. In genealogie too IMHO. Another example, King LOUIS XIV is on trône 14.051643 to 01.09.1715 : In Delta Days I get 26407 days, with YMD I get 72 years 3 months 18 days, it is more speaking, in this case only years are importants yes. I submit, in the past, to forum a littlle routine that convert number of days to ymd. So I agree with you but depending of the point of view ! Gérard. Gérard. |
|||
10-19-2015, 02:06 PM
Post: #4
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
Be careful what you ask for around here.
I'm expecting a short clever routine that generates years, months, weeks, days, hours, minutes and seconds. And I'm expecting to see it in 0.00000001417 milli-centuries. 2speed HP41CX,int2XMEM+ZEN, HPIL+DEVEL, HPIL+X/IO, I/R, 82143, 82163, 82162 -25,35,45,55,65,67,70,80 |
|||
10-19-2015, 02:43 PM
Post: #5
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
Well, Already on the net, of course you know this !
LOL Gérard. |
|||
10-21-2015, 01:10 PM
(This post was last modified: 10-21-2015 01:33 PM by Dieter.)
Post: #6
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
(10-19-2015 09:33 AM)ggauny@live.fr Wrote: I wonder if it's a way to load in one list the "31 STO 01 STO 03 etc.", I've check anywhere but I don't find. You do not need a list, you can compute the number of days in a month directly. It's just 12 steps on the 34s: Code: 01 RCL X If you perfer a closed formula instead of a test: n = 28 + (m + m div 8) mod 2 + 2 · abs(sign(m–2)). And if February is neglected (:= 30 days) it even boils down to 30 + (m + m div 8) mod 2. By the way... (10-19-2015 09:33 AM)ggauny@live.fr Wrote: This routine is precise because we work with really numbers of days into month ...in many cases there is no "precise" result. The number of days depends on how you count them. This was already discussed in march when we have been talking about this topic in another thread (cf. post #9 and #12). Dieter |
|||
10-21-2015, 01:49 PM
Post: #7
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
Thanks Dieter for comments, but I really don't understand how works #. I've tried somme example from goods programers like you, but I don't understand.
With my new owner manual, I hope understand... Good day. Gérard Gérard. |
|||
10-21-2015, 06:07 PM
Post: #8
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
(10-21-2015 01:49 PM)ggauny@live.fr Wrote: Thanks Dieter for comments, but I really don't understand how works #. Lines starting with a "#" are constants from the CONST menu (h ENTER). For instance, #c is the constant c from this menue, i.e. the speed of light. As a special feature, integers from 0 to 255 can also be entered this way so that they fit in a single line and execute somewhat faster. To enter such a constant, select "# 0 to 255" from the constants menu. This is the very last entry, so simply press "1" to get to the first constant "1/2", then press the up-arrow to move back to the last menu entry, which is "# 0 to 255". After pressing ENTER simply type the number you want, e.g. "123" or "008". Of course the constants #002 and#008 can just as well be entered as a simple 2 resp. 8, but using the constants here is good pratice as this runs a tiiiiiiiny bit faster. ;-) Dieter |
|||
10-21-2015, 07:22 PM
(This post was last modified: 10-22-2015 12:30 PM by Dieter.)
Post: #9
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
(10-19-2015 09:33 AM)ggauny@live.fr Wrote: Hi, I've ported routine of mine from HP41cx to WP34s. Your program obviously uses a 0 or 1 in register D as a kind of carry bit. This can be done in a simple and more effective way by using a flag. Here is my version for the 34s. It computes the number of days in a month according to the previously posted formula. Flag 00 serves as a kind of carry flag. Code: 01 LBL"YMD" Using the WP34s ΔDAYS function, the code gets a bit shorter: Code: 01 LBL"YMD" Edit: corrected an error in the final steps of both programs. In both cases your Louis XIV example returns 72,0318, i.e. 72 years, 3 months and 18 days. As usual, comments and corrections are welcome. Dieter |
|||
10-22-2015, 05:16 AM
Post: #10
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
Hi,
Wowww ! I wonder how is it possible to write so quickly this kind of complicated codes !!! Of course thank again, I understant better when I se an example and I 'm studiying these elegants and shorts examples. May be it's what Walter Bonin would say the other day with the Delta DAYS command ? Surely but I had no understood at this time. Thanks for help and "private school" ! Gérard. Gérard. |
|||
10-22-2015, 06:40 AM
Post: #11
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
(10-21-2015 06:07 PM)Dieter Wrote: Of course the constants #002 and#008 can just as well be entered as a simple 2 resp. 8, but using the constants here is good pratice as this runs a tiiiiiiiny bit faster. ;-) I'd say significantly faster knowing the two different code paths involved. Of course neither takes all that long for fast CPU in the 30b unless you do them a lot of times. - Pauli |
|||
10-22-2015, 06:49 AM
Post: #12
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
Don't be too surprised by the rapidity of coding, Dieter has a lot of experience writing programs for the 34S. He is definitely one of the best around and, I believe, better than I am at this despite the fact that I wrote the bulk of the 34S firmware!
- Pauli |
|||
10-22-2015, 10:19 AM
Post: #13
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
Hi,
I AGRRE WITH YOU SIR § Gérard. |
|||
10-22-2015, 11:44 AM
Post: #14
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
Hallo Dieter,
In your "YMD" version WP 34s, I think it would be better to code step 47 with "DEC Y" and not with "DEC X". With "DEC X" I get an error of plus one year (comparing with my 3 HP 41, one C and two CX, also with my HP 50g). But may be have-I miss understanding something in your code. In this case I many beg your pardon. Mister Dale, say that you are the best programer for WP 34s, I think so too ! Programing has so changed since my HP 25 not C and my HP 67 !!!! Gérard. Gérard. |
|||
10-22-2015, 12:19 PM
(This post was last modified: 10-22-2015 12:41 PM by Dieter.)
Post: #15
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
(10-22-2015 11:44 AM)ggauny@live.fr Wrote: In your "YMD" version WP 34s, I think it would be better to code step 47 with "DEC Y" and not with "DEC X". With "DEC X" I get an error of plus one year It would be better to use the correct solution. #-) Sorry, the listing at this point had two lines mixed up (probably due to a copy&paste error). Changing the code to DEC Y is not the solution. The last RCL 01 command of course has to move three lines below, right before YEAR. I now have corrected both listings, and I also added a change in the second version (line 14 ff.) that saves two steps. Dieter |
|||
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
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 |
|||
10-22-2015, 04:53 PM
Post: #17
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
Hi,
Thanks for your routine, it is a festival of so hight programmation ! All people and I say to you, Dieter and Wolfgang, a great "merci", we learn so well with you for programming. You are so goods professors ! It is always time to learn. In the other hand, what a work to understand how you raisonnez ! (reason ?), and look at the Bonin's manual to understand all of yours steps ! Again very thanks, I have "du pain sur la planche !" Gérard. Gérard. |
|||
10-22-2015, 06:02 PM
(This post was last modified: 10-22-2015 06:03 PM by Dieter.)
Post: #18
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
(10-22-2015 04:00 PM)Didier Lachieze Wrote: The program from Dieter is extremely well done. However it’s still possible to squeeze out a few steps Ah, great. I like the idea with the complex STO–.03 which calculates y2–y1 and m2–m1 in one single step. The program now is eight lines shorter. AFAIK this is equivalent to the memory consumption of two data registers, but on the other hand the program requires three additional (local) registers... ;-) As far as I can see R.00 seems to remain unused, so LocR 004 (with adjusted register addresses) should be fine as well. Or do I miss something here? Dieter |
|||
10-22-2015, 09:46 PM
Post: #19
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
(10-22-2015 06:02 PM)Dieter Wrote: The program now is eight lines shorter. AFAIK this is equivalent to the memory consumption of two data registers, but on the other hand the program requires three additional (local) registers... ;-) As far as I can see R.00 seems to remain unused, so LocR 004 (with adjusted register addresses) should be fine as well. Or do I miss something here? You're right. Here is an updated version and with some improvements in the beginning it's even 3 steps shorter : Code: 01 LBL"YMD" ; stack: date2, date1 Notes:
|
|||
10-23-2015, 11:25 AM
Post: #20
|
|||
|
|||
RE: Year(s) Month(s) Day(s) between 2 dates
With some changes starting step 28, one step less, now 37 lines (and 4 local registers):
Code: 01 LBL"YMD" ; stack: date2, date1 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 22 Guest(s)