Kbase P123005: Retrieving time to millisecond precision
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  2/8/2008 |
|
Status: Unverified
GOAL:
How to get milliseconds in the 4GL
GOAL:
How to get sub second time measurement from the 4GL
GOAL:
How to retrieve time with milliseconds
FACT(s) (Environment):
Windows
UNIX
Progress 9.x
OpenEdge 10.x
FIX:
OpenEdge 10.x:
The introduction of MTIME() in OpenEdge 10 allows millisecond precision when retrieving TIME. For example, the following will return the current time with millisecond precision:
MESSAGE STRING(TIME, "HH:MM:SS:") + STRING( MTIME(DATETIME( TODAY, MTIME )) MODULO 1000, "999") VIEW-AS ALERT-BOX INFO BUTTONS OK.
Progress 9.x:
Prior to OpenEdge 10, millisecond precision can be achieved through an external API call. The following are examples from WINDOWS and UNIX operating systems:
1. In WINDOWS this can be achieved with a Win32 API call to GetLocalTime:
/*----------------------------------------------------*/
DEF VAR systime AS MEMPTR NO-UNDO .
DEF VAR i AS INTEGER.
DEF VAR lTime AS CHAR FORMAT "X(20)".
PROCEDURE GetLocalTime EXTERNAL "KERNEL32.DLL".
DEFINE OUTPUT PARAMETER systime AS MEMPTR.
END.
SET-SIZE(systime) = 16.
RUN GetLocalTime (OUTPUT systime).
/* The structure brings information of the date and hour, if only hours is required then we use only the last bytes */
ltime = STRING (GET-BYTE(systime,9)) .
ltime = ltime + ":" + STRING (GET-BYTE(systime,11)) .
ltime = ltime + ":" + STRING (GET-BYTE(systime,13)) .
ltime = ltime + "." + STRING (GET-BYTE(systime,15)) .
MESSAGE lTime VIEW-AS ALERT-BOX.
SET-SIZE(systime) = 0.
/*----------------------------------------------------*/
2. On UNIX a C Program could be used to get and return the Time in milliseconds as a String. The value can then be retrieved by the 4GL with a INPUT THROUGH statement.