Kbase P117912: 4GL: How to convert the STRING(TIME,"HH:MM:SS") back to its original INTEGER value?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/08/2006 |
|
Status: Unverified
GOAL:
4GL: How to convert the STRING(TIME,"HH:MM:SS") back to its original INTEGER value?
GOAL:
How to convert the CHARACTER representation of time back to its INTEGER representation?
GOAL:
How to convert a time CHARACTER string formatted as "HH:MM:SS" to a TIME INTEGER value.
FIX:
The 4GL TIME function returns an integer representing the time in seconds. If the TIME function has no arguments, it returns the number of seconds since midnight. The TIME function may be used with the STRING function to obtain a CHARACTER representation that gives the time in hours, minutes, and seconds, that is in the "HH:MM:SS" FORMAT. The following procedure demonstrates
1. How to obtain the current time as an INTEGER value.
2. How to use the TIME function with the STRING function to obtain a CHARACTER representation of the time in the "HH:MM:SS" FORMAT.
3. How to convert a TIME CHARACTER representation in the "HH:MM:SS" FORMAT back to its original INTEGER value.
DEFINE VARIABLE iIntegerTime AS INTEGER NO-UNDO.
DEFINE VARIABLE cStringTime AS CHARACTER NO-UNDO.
DEFINE VARIABLE iStringBackToInteger AS INTEGER NO-UNDO.
/* Get current TIME as INTEGER */
iIntegerTime = TIME.
/* Convert it to CHARACTER */
cStringTime = STRING(iIntegerTime,"HH:MM:SS").
/* Convert it back to INTEGER */
iStringBackToInteger = INTEGER(SUBSTRING(cStringTime, 1, 2)) * 60 * 60 +
INTEGER(SUBSTRING(cStringTime, 4, 2)) * 60 +
INTEGER(SUBSTRING(cStringTime, 7,2)).
/* Display all */
MESSAGE
"Display the TIME as INTEGER:" "~t~t" iIntegerTime "~n"
"Convert INTEGER TIME to CHARACTER:" "~t" cStringTime "~n"
"Convert CHARACTER TIME to INTEGER:" "~t" iStringBackToInteger
VIEW-AS ALERT-BOX INFO BUTTONS OK.