Page 1 of 1

User Variable Activity syntax for timestamp

Posted: Sun Jul 08, 2018 7:00 am
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?

Posted: Sun Jul 08, 2018 8:01 am
by chulett
So, you need a string in that format? What have you tried?

Posted: Sun Jul 08, 2018 8:59 am
by sivakr4056@gmail.com
Yes, that's right.

Posted: Sun Jul 08, 2018 11:07 am
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.

Posted: Sun Jul 08, 2018 11:11 am
by chulett
And just in case you haven't seen this yet, here's a starting point in the online help for the stage.

Posted: Mon Jul 09, 2018 12:26 am
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.

Posted: Tue Jul 10, 2018 6:07 am
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?