Consultor Eletrônico



Kbase P16206: How to convert a time string to a time value?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   02/02/2003
Status: Unverified

GOAL:

How to convert a time string to a time value?

FIX:

The following function takes a time string of the form HH:MM:SS and returns the number of seconds elapsed since midnight (that is the value returned by the Progress 4GL TIME function:

FUNCTION getTime RETURNS INTEGER (INPUT cTime AS CHARACTER):

DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DEFINE VARIABLE iTotal AS INTEGER NO-UNDO.

DO iCounter = 1 TO NUM-ENTRIES(cTime, ":"):
iTotal = iTotal + INTEGER(ENTRY (iCounter, cTime, ":")) * EXP(60, 3 - iCounter).
END.
RETURN iTotal.
END FUNCTION.

MESSAGE getTime ("21:04:11")
VIEW-AS ALERT-BOX INFO BUTTONS OK.