Post Reply 
24hr Time Calculations
05-17-2022, 06:18 PM
Post: #1
24hr Time Calculations
Anybody have a good program for calculating the elapsed time between two times? As an example, in HHMMSS format,

090000
to
163200
is
7h32m

My particular use case is on a DM42, so any HP42 program should work fine, but I can't seem to find one out there. My intent is to take the program and integrate the sum feature, so I can add the resultant elapsed times to those registers and use the stats features on them.
Visit this user's website Find all posts by this user
Quote this message in a reply
05-17-2022, 07:25 PM
Post: #2
RE: 24hr Time Calculations
Does it have the HMS- function like the 41cx (and probably the Time module too)?

http://WilsonMinesCo.com (Lots of HP-41 links at the bottom of the links page, http://wilsonminesco.com/links.html )
Visit this user's website Find all posts by this user
Quote this message in a reply
05-17-2022, 07:38 PM
Post: #3
RE: 24hr Time Calculations
Page 84 in the HP42s OM

My calculators - former: CBM PR100, HP41CV, HP11C, HP28S - current: HP48G, HP35S, Prime, DM41X, DM42, HP12C
Find all posts by this user
Quote this message in a reply
05-17-2022, 07:44 PM (This post was last modified: 05-17-2022 07:44 PM by Steve Simpkin.)
Post: #4
RE: 24hr Time Calculations
As Garth and Peet mentioned, no programming necessary. The HP-42S/DM42/Free42 does have the HMS+ and HMS- functions. They use the HH.MMSSss format for time entry. Use FIX 4 (for HH.MM.SS) of FIX 6 (for HH.MM.SSss) display format for best results.

For your example type :
16.3200 [ENTER] 9.0000 [HMS-]
The answer is 7.3200 (with the display set to FIX 4).
You might want to assign the HMS+ and HMS- functions to the Custom menu if you use them frequently.


Attached File(s) Thumbnail(s)
   
Visit this user's website Find all posts by this user
Quote this message in a reply
05-17-2022, 07:55 PM
Post: #5
RE: 24hr Time Calculations
As others have mentioned, the HMS- function is already there, but keep in mind it will return results that are also in HH.MMSS format (meaning you can't sum those directly). You'll need to use the →HR function to convert from HH.MMSS to decimal hours, then you can sum up those results.
Visit this user's website Find all posts by this user
Quote this message in a reply
05-17-2022, 10:01 PM
Post: #6
RE: 24hr Time Calculations
Thanks all, this is exactly what I needed! I'll whip up a quick program around this function and be set!
Visit this user's website Find all posts by this user
Quote this message in a reply
05-17-2022, 11:56 PM
Post: #7
RE: 24hr Time Calculations
Ok, so now I started with the following, which I'll loop later:
Code:

00 { 52-Byte Prgm }
01▸LBL "TMSHT"
02 INPUT "DAY END"
03 INPUT "DAY START"
04 RCL "DAY END"
05 RCL "DAY START"
06 HMS-
07 →HR
08 Σ+
09 END

But I get a "Nonexistent" from Free42. This is literally my second program in a 42s ever... any debug ideas?
Visit this user's website Find all posts by this user
Quote this message in a reply
05-18-2022, 01:27 AM
Post: #8
RE: 24hr Time Calculations
Your program works fine when I copied and pasted it into Free42.
However it shortened the 2nd variable "DAY START" to "DAY STA":
Code:
00 { 48-Byte Prgm }
01▸LBL "TMSHT"
02 INPUT "DAY END"
03 INPUT "DAY STA"
04 RCL "DAY END"
05 RCL "DAY STA"
06 HMS-
07 →HR
08 Σ+
09 END

You get a "Nonexistent" message if the variable isn't created yet but the program wants to access it.
This might happen for instance if the program starts at line 04.

In such a case you can single step through the program with the SST or just the ▼ key.
While you press down the key the current line is displayed:
Code:
03 INPUT "DAY STA"
04▶RCL "DAY END"

HTH
Find all posts by this user
Quote this message in a reply
05-18-2022, 01:29 AM
Post: #9
RE: 24hr Time Calculations
(05-17-2022 11:56 PM)syzygetic Wrote:  Ok, so now I started with the following, which I'll loop later:
Code:

00 { 52-Byte Prgm }
01▸LBL "TMSHT"
02 INPUT "DAY END"
03 INPUT "DAY START"
04 RCL "DAY END"
05 RCL "DAY START"
06 HMS-
07 →HR
08 Σ+
09 END

But I get a "Nonexistent" from Free42. This is literally my second program in a 42s ever... any debug ideas?

Your program seems to work as-is for me in Free42. I copied and pasted it into both mobile and desktop versions of Free42 and it works fine.
Visit this user's website Find all posts by this user
Quote this message in a reply
05-18-2022, 03:10 AM
Post: #10
RE: 24hr Time Calculations
Interesting, thanks guys! This is my first time using winFree42 so maybe I have some setting messed up. I'll load it up on the real thing tomorrow and develop a bit more.
Visit this user's website Find all posts by this user
Quote this message in a reply
05-18-2022, 07:55 AM
Post: #11
RE: 24hr Time Calculations
(05-18-2022 01:27 AM)Thomas Klemm Wrote:  However it shortened the 2nd variable "DAY START" to "DAY STA":

on the 42s a variable name can have one to seven characters

My calculators - former: CBM PR100, HP41CV, HP11C, HP28S - current: HP48G, HP35S, Prime, DM41X, DM42, HP12C
Find all posts by this user
Quote this message in a reply
05-18-2022, 11:34 AM
Post: #12
RE: 24hr Time Calculations
Indeed, it was the variable length, thanks. I shortened it up and Free42 and the DM42 both like this now. On to looping!

Code:

00 { 40-Byte Prgm }
01▸LBL "TMSHT"
02 INPUT "DEND"
03 INPUT "DSTART"
04 RCL "DEND"
05 RCL "DSTART"
06 HMS-
07 →HR
08 Σ+
09 END

Thanks all, great forum here!
Visit this user's website Find all posts by this user
Quote this message in a reply
05-18-2022, 08:35 PM
Post: #13
RE: 24hr Time Calculations
Glad, we could help.

(05-17-2022 11:56 PM)syzygetic Wrote:  This is literally my second program in a 42s ever...

This is amazing. I started programming on an HP-41CV as a teenager in the 80's.
All I had was curiosity, excellent manuals, and plenty of time.
I can hardly imagine what that would be like for me today.

However, I wish you a lot of fun on your journey.

It piqued my interest as to what might have caused the problem.
So, I encoded your program with the DM42 Programming tool.
And lo and behold, it doesn't shorten the name of the variable.

I downloaded the .raw file into Free42 and ran your program and got the same error message:
Nonexistent

It seems that the INPUT "DAY START" command creates a variable with a corrupted name.
These are the two variables, if they are used in a program:
Code:
00 { 20-Byte Prgm }
01 RCL "DAY END"
02 RCL "DAY STA├├"
03 END

No wonder that this can't be found.
Find all posts by this user
Quote this message in a reply
05-19-2022, 02:21 PM
Post: #14
RE: 24hr Time Calculations
(05-18-2022 08:35 PM)Thomas Klemm Wrote:  This is amazing. I started programming on an HP-41CV as a teenager in the 80's.
All I had was curiosity, excellent manuals, and plenty of time.
I can hardly imagine what that would be like for me today.

I have to say, the manuals are indeed excellent. I have a lot of experience with other languages, just nothing in RPN/RPL, and really nothing stack based, such as FORTH. It's refreshingly simple, though, even if it's a lot more encumbered here because of the need to compile, them import to an emulator or calculator. I do wish there were a command line utility I could use for development work, just to reduce the turnaround time on debugging like this.
Visit this user's website Find all posts by this user
Quote this message in a reply
05-19-2022, 03:11 PM (This post was last modified: 05-19-2022 03:33 PM by Thomas Klemm.)
Post: #15
RE: 24hr Time Calculations
(05-19-2022 02:21 PM)syzygetic Wrote:  I do wish there were a command line utility I could use for development work, just to reduce the turnaround time on debugging like this.

There's an extension for VS Code you might consider:
(12-19-2018 04:48 PM)Heilingbrunner Wrote:  More details see Visual Studio Code Marketplace - HP42S-free42.

This linked thread might be of interest as well: Txt to Raw and Raw to Txt
Find all posts by this user
Quote this message in a reply
05-22-2022, 12:34 PM
Post: #16
RE: 24hr Time Calculations
There's yet another way: (Free42) txt2raw - raw2txt
Find all posts by this user
Quote this message in a reply
Post Reply 




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