Seconds to Time

This seems like it would be a common thing people are doing and I should be able to figure it out. A little help on the brain power and posting so that others can find the answer quicker might not be a bad idea though.
This is my current code which isn’t all that pretty I’m aware. Suggestions of any kind won’t hurt my feelings.

FYI This timer is reset on a daily basis. (Via some separate code.)

PauseTimer (Timer_Conveyor_Stopped_Current);
Int_Stop_time_in_Seconds = GetRestartTimer(Timer_Conveyor_Stopped_Current);
StopTimer (Timer_Conveyor_Stopped_Current);

int_stopped_hours = Int_Stop_time_in_Seconds/3600;
Stopped_Time_String_Finished= Stopped_Time_String; //has Hours

int_stopped_Minutes = (Int_Stop_time_in_Seconds-(int_Stopped_Hours*3600))/60;
Stopped_Time_String_Finished= Stopped_Time_String_Finished + ":" + Stopped_Time_String;//has Minutes

int_Stopped_Seconds = (Int_Stop_time_in_Seconds-(int_Stopped_Hours*3600)-(int_Stopped_Minutes*60));
Stopped_Time_String_Finished= Stopped_Time_String_Finished + ":" + Stopped_Time_String;//has Seconds

//display Stopped_Time_String_Finished by putting in a table element/string shown by display
// or even showing "Stopped_Time_String_Finished".

Any Opto-mizations suggested?

Two suggestions…

Firstly, for the seconds to h:m:s I would use the code from the Doc 1701, Pac Control Command Reference.
Page 573. Get Seconds Since Midnight. (If you are in Pac Control, click on Help, Manuals, Command Reference).

To find elapsed time in HOURS, MINUTES, SECONDS since midnight using standard commands:
Move the seconds to an integer 32 variable: TEMP_VAR
Divide TEMP_VAR by: 3600 and move to: HOURS
MODULO TEMP_VAR by: 3600 and move to: TEMP_VAR
Divide TEMP_VAR by: 60 and move to: MINUTES
MODULO TEMP_VAR by: 60 and move to: SECONDS.

To find the same thing using OptoScript code:

TEMP_VAR = GetSecondsSinceMidnight();
HOURS = TEMP_VAR / 3600;
MINUTES = (TEMP_VAR % 3600 / 60;
SECONDS = (TEMP_VAR % 3600) % 60;

In your case, just put;
Temp_Var = Int_Stop_time_in_Seconds;

Secondly, have you thought about using the command ‘Get Off-Time Totalizer’?
(Perhaps you do not have a digital point you are using to turn off the conveyor?)

Third (Ok, its an after thought), but the converting to a string to display… Why? You can display Ints just fine, so just put the H M S on the display as three variables… Done?

Could you give us the “bigger picture” of what you’re solving here? E.g.: “I’m building a display where I want to show how long it took too…” or some such, for some context.

You might also want to check out [U][B]this related post on elapsed time[/B][/U]. The code I shared there was a little more complicated since that timing could last for days (and I didn’t quite get the leap year thing right initially – so you’d have a problem after 350 years, so be sure to get Philip’s fix later in the thread if you use that)!

But I like Ben’s idea – check out the off-time totalizer feature that’s built into the I/O unit – our brains are smart, let them do the timing for you!

I knew I was doing it the hard way. I’m doing a couple different timers on the same point, clearing them at different times: day, shift, current downtime. (Which is why I didn’t switch outright to a totalizer.) I’m also editing someone else’s strategy which is why I don’t just leave them as Ints to display them. They like having a single place (a string table) where all operator messages are displayed and then shifted before a new message in order to retain a history of the messages.

Thanks for your help.

Somewhat related, on scheduling: check out [U][B]this clever method[/B][/U] developed by one of our regular contributors, where he packs a bunch of time/date info into a string for scheduling (an HVAC system in his case).