Resolved How to convert fraction of time into HH:MM:SS

Cecil

19+ years progress programming and still learning.
I'm having a complete mental bock on how to calculate a fraction in to Hours, Minutes and Seconds. I'm importing data from an XML file where time is stored as a fraction. So for example: 0.25 = 6:00:00, 0.50 = 12:00:00 1.00 = 24:00:00.

Now how do I convert 1.42629629629629, into Hours Minutes and Seconds? Also the time records can exceed 24 hours as the data is represented as accumulation of time. So it's quite possible to have 55:45:23.
 

Cecil

19+ years progress programming and still learning.
I believe I figured it out but I'm not sure if I've got some rounding issues.

Here is my code below, please feel free to see what improvements can be made .

Code:
FUNCTION CONVDECTOTIME RETURN CHARACTER
  (INPUT deTime AS decimal):

  DEFINE VARIABLE deSeconds  AS DECIMAL  NO-UNDO.
  DEFINE VARIABLE insec  AS INTEGER  NO-UNDO.
  DEFINE VARIABLE INMIN  AS INTEGER  NO-UNDO.
  DEFINE VARIABLE INHours  AS INTEGER  NO-UNDO.
  DEFINE VARIABLE INDays  AS INTEGER  NO-UNDO.
  DEFINE VARIABLE chString  AS CHARACTER  NO-UNDO.
   
  ASSIGN
  deSeconds = DETIME * (60 * 60 * 24)
  INHours  = INTEGER(TRUNCATE(deSeconds / (60 * 60),0))  
  INMIN  = INTEGER(TRUNCATE(deSeconds / 60,0)) MOD 60
  insec  = deSeconds MOD 60
  INDays  = deSeconds / ( 60 * 60 * 24).

  chString = SUBSTITUTE("&1:&2:&3",
  STRING(INHours, ">,>>9"),
  STRING(INMIN, "99"),
  STRING(insec, "99")
  ).

  RETURN chString.

END FUNCTION.

MESSAGE CONVDECTOTIME( 1.2537731481481482) SKIP
        CONVDECTOTIME( 1.4262962962962964) SKIP
        CONVDECTOTIME( 1.25) SKIP
    view-as alert-box info.
 
Last edited:
Top