Convert varchar to timestamp

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
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Convert varchar to timestamp

Post by sam334 »

Have one more question again,

Have a job where input is SQL db and output is DB2 db. There appointment date is Varchar,12 in SQL db with the format of 201403021500 which I am trying to convert as 03/02/2014 3.00 PM (Timestamp)

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

Post by chulett »

The "timestamp" part is the important part, not the specific format you posted. Have you tried using the StringToTimestamp function? What issues are you facing?
-craig

"You can never have too many knives" -- Logan Nine Fingers
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

Craig,
I used StringToTimeStamp(Input,"%mm/%dd/%yyyy %hh:%nn:%ss")

Is this correct? In transformer, it is not accepting it. Neither in Stagevariable.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Classic problem - the format mask you use in the function needs to match the format of the incoming string, not any perceived output format. Timestamps don't have an internal format so it just needs to know how to parse the string to turn it into a timetamp.
-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 »

OK, hold on... is this a Server job as posted? If so, my bad, lost track of what forum we were in - that function is a Parallel function, which would be why it would not be "accepted". You'd either need to work with IConv/OConv or just substring it apart and put it back together in the format that you need.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

Thanks Craig. Unfortunate I can't see the explanation as my premium membership is still not activated. Its been almost a month gone, have sent lots of emails to admin. Not yet done..
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Opened them.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

Craig,
Thanks a lot. I thought so. We have all the way top to bottom OCON/INCONV floating... lol.

Now, I used the below substrings function, which transformer is not accepting. Anything wrong with the "" in transformer.

As input is 201302031500, and output is 03/02/2013 3.00Pm.I used,

SUBSTRINGS(input,1,4):''-'':SUBSTRINGS(input,5,2):''-'':SUBSTRING(input,7,2):'' '':SUBSTRINGS(input,9,2):'':'':SUBSTRINGS(input,11,2):'':00''

Any thought.
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

Never mind.. Got it solved... Thanks a lot.. Appreciate as always...
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Except that the middle one needs to be SUBSTRINGS (I assume you made a typo here) that will work.

Another possbility - which I believe is better self-documented - is

Code: Select all

Fmt(InLink.TheValue, "L####-##-## ##:##:00") 
Last edited by ray.wurlod on Thu Apr 10, 2014 5:11 pm, edited 1 time 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I prefer the operator over the function, but six of one...

input[1,4]:''-'':input[5,2]:''-'':input[7,2]: <etc>
-craig

"You can never have too many knives" -- Logan Nine Fingers
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

Thanks Craig and Ray. It worked perfectly.
Post Reply