Getting the Current timestamp with fractional milliseconds

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You will need to declare your Timestamp column with the extended attribute of "microseconds" in order to store fraction seconds.
lindatgeorge
Participant
Posts: 34
Joined: Mon Jun 15, 2009 12:16 am
Location: Bangalore

Post by lindatgeorge »

The column is already declared like that to accomdate fractional milliseconds
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Why not use the derivation of "CurrentTimestampMS()", that works for me.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What flavor of UNIX? From what I recall, not all support milliseconds from the system time.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Sreenivasulu
Premium Member
Premium Member
Posts: 892
Joined: Thu Oct 16, 2003 5:18 am

Post by Sreenivasulu »

They do not support from the date function called from shell prompt.

But you use a c function in unix you can get milliseconds

e.g in linux gettimeofday can be used for this purpose

Regards
Sreeni
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

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.

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.
Post Reply