User Variable Activity syntax for timestamp

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
sivakr4056@gmail.com
Participant
Posts: 4
Joined: Thu Jul 05, 2018 5:57 pm

User Variable Activity syntax for timestamp

Post by sivakr4056@gmail.com »

Hi, i need to create current timestamp in (YYYY-MM-DD HH:MM:SS.ssssss) in User Variable Activity. Can anyone tell me the proper syntax to create a current timestamp in required format?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So, you need a string in that format? What have you tried?
-craig

"You can never have too many knives" -- Logan Nine Fingers
sivakr4056@gmail.com
Participant
Posts: 4
Joined: Thu Jul 05, 2018 5:57 pm

Post by sivakr4056@gmail.com »

Yes, that's right.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Well, at least one of the two questions were answered. :?

Have you done any BASIC programming of routines or job control code yet? Any experience with the System Variables? @DATE comes to mind but AFAIK it won't handle the milliseconds that you say you need. One would typically pair that with OConv() to convert it to an external format. You may need to leverage a call to your O/S to get a timestamp with milliseconds, what flavor of UNIX do you have and are there any functions available there you could use?

I'm sure others will chime in with thoughts but those are the first things that come to mind.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And just in case you haven't seen this yet, here's a starting point in the online help for the stage.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Microseconds are not available in the function set available to user variable expressions.

I would suggest using an Execute Command activity, to execute the UNIX date command with appropriate arguments. For example (AIX):

Code: Select all

date +%Y-%m-%dT%H:%M:%S.%s
Pipe the result through tr if you need to change the "T" to a space. Pipe the result through cut if you don't need all of the fractional second digits.
Last edited by ray.wurlod on Thu Jul 12, 2018 1:23 pm, edited 2 times in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

On AIX, if you want a space in the middle, then use double quotes:

Code: Select all

date "+%Y-%m-%d %H:%M:%S"
Watch out for the %s option though as that is not fractional seconds, rather it is the number of seconds since 1/1/1970. I do not think the AIX date command has an option for fractional seconds. Searching suggests to write a little perl or C program to provide the resolution you need. That really seems like overkill to me!

As Craig had asked before, what version of Linux/UNIX is being used?

Also, can you just use zeros for the fractional second portion?
Choose a job you love, and you will never have to work a day in your life. - Confucius
Post Reply