Handling time with variable length

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
sharmabhavesh
Premium Member
Premium Member
Posts: 38
Joined: Tue Jun 19, 2012 11:03 pm
Location: India

Handling time with variable length

Post by sharmabhavesh »

Hi,
I have a time field which can either be hhmmss or hmmss. The hour field can be 1-2 digits without a '0' being prefixed. How can I convert such string to time. I used %(h,s)nnss but that didn't work.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I assume that you actually have a string field, since time fields don't have a format (they are stored as binary numbers).

Simply prefix the string with a "0" character and use the rightmost six characters of the result, with "%hh%nn%ss" as the format string.

Code: Select all

Right("0" : InLink.TimeString, 6)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sharmabhavesh
Premium Member
Premium Member
Posts: 38
Joined: Tue Jun 19, 2012 11:03 pm
Location: India

Post by sharmabhavesh »

Hi Rar, Thanks for the solution. But can this be handled by specifying a format string. Read at some Datastage documentation to use %(h,s) in the format string but didn't work in my case.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The "s" means it can have a leading space. If "1-2 digits without a leading 0" means "1 thru 12" you can just use %h I would think.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply