How To Convert Hh:mm:ss To Seconds

Pramod Nair

Member
I am trying to convert hour minute second to seconds but unable to convert. I have character variable which has initial value ('01:33:10'). But dont know how to convert the given time into its equivalent seconds i.e. 5590 in progress coding.
Help needed.
Thanks in advance.
 
This will do what you require, but I do not know if there is a built-in Progress function that does it better:
Code:
DEFINE VARIABLE vSeconds AS INTEGER LABEL "Total Seconds" NO-UNDO.
DEFINE VARIABLE vTime AS CHARACTER INITIAL "01:33:10" NO-UNDO.

vSeconds = INT(SUBSTR(vTime,1,2)) * 3600
         + INT(SUBSTR(vTime,4,2)) * 60
         + INT(SUBSTR(vTime,7,2)).

DISPLAY vSeconds.
 
An alternative, using the datetime function:

Code:
def var ctime as char init "01:33:10".

message 
    interval( 
        datetime( string( today ) + " " + ctime ),
        today,
        "seconds"
     )        
view-as alert-box.
 
Back
Top