Getting the Current timestamp with fractional milliseconds
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 34
- Joined: Mon Jun 15, 2009 12:16 am
- Location: Bangalore
-
- Premium Member
- Posts: 892
- Joined: Thu Oct 16, 2003 5:18 am
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
You can use a server routine.
If $OPTIONS TIME.MILLISECOND is set, then SYSTEM(12) returns the current time in milliseconds since midnight, provided that the operating system supports milliseconds.
If $OPTIONS TIME.MILLISECOND is set, then SYSTEM(12) returns the current time in milliseconds since midnight, provided that the operating system supports milliseconds.
Code: Select all
FUNCTION NowMS(Format)
$COPYRIGHT "Copyright (c) 2004, Ray Wurlod. All rights reserved. May be freely used with this copyright notice intact."
$OPTIONS TIME.MILLISECOND
Equate DP To "." ; * change for different locale
Now = System(12) ; * internal format
Time = Time()
If Time = Now
Then
MS = "000" ; * milliseconds not supported
End
Else
MS = Mod(Now,1000) ; * milliseconds portion of time
End
Begin Case
Case UnAssigned(Format) Or IsNull(Format)
Ans = @NULL
Case Format = 0 ; * internal format
Ans = Now/1000
Case Format = 1 ; * time format (HH:MM:SS.sss)
Ans = Oconv(Now/1000, "MTS") : DP : MS
Case Format = 2 ; * timestamp format using today's date
Ans = Oconv(Date(), "D-YMD[4,2,2]") : " " : Oconv(Now/1000, "MTS") : DP : MS
Case @TRUE
Ans = @NULL
Call DSTransformError("Invalid format argument.", "NowMS")
End Case
RETURN(Ans)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.