Timestamp Format

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
major
Premium Member
Premium Member
Posts: 167
Joined: Mon Nov 26, 2007 12:21 am

Timestamp Format

Post by major »

Hi all,

I need timestamp in below format

Code: Select all

MM/DD/YYYY HH:MM:SS AM/PM
Currently I am using below function

Code: Select all

OCONV(DATE(),"D/MDY[2,2,4]") :" " : UPCASE(OCONV(TIME(),"MTHS"))
Is there any better way to do it as the function I'm using is appending seconds with AM/PM

Eg:-01/01/2010 12:12:12AM --> 01/01/2010 12:12:12 AM

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

Post by ray.wurlod »

Lose the "H" from the time conversion, which specifies a 12-hour clock. No "H" specifies a 24-hour clock.

Code: Select all

OCONV(DATE(),"D/MDY[2,2,4]") :" " : OCONV(TIME(),"MTS")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
major
Premium Member
Premium Member
Posts: 167
Joined: Mon Nov 26, 2007 12:21 am

Post by major »

Ray,

Actually I need a 12 hour clock with AM/PM

Thanks,
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Which is what you have, so you're good there. The issue is the fact that there's no space in front of the AM/PM, not sure why it wants to run the two together but it does. As far as I know, you need to split the result and insert the space yourself, which is easy since the output is a fixed size.
-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 »

Ah. I misunderstood. As noted, take the left 19 characters, a space and the right two characters. Use a stage variable to avoid calculating the timestamp twice.

Code: Select all

svTimestamp  <--  Oconv(Date(),"D/MDY[2,2,4]" : " " : Upcase(Oconv(Time(),"MTHS"))

Left(svTimestamp,19) : " " : Right(svTimestamp.2)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
major
Premium Member
Premium Member
Posts: 167
Joined: Mon Nov 26, 2007 12:21 am

Post by major »

Thanks guys.. :D
Post Reply