Timestamp conversion

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
Sgiri1
Participant
Posts: 43
Joined: Sat Nov 08, 2008 10:58 pm
Location: Tambaram

Timestamp conversion

Post by Sgiri1 »

hi please let me know how to do following time stamp conversion.

My i/p is 2009-08-05 23:35:06

and the required o/p is mm/dd/yyyy hh:mi:ss AM
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

What have you tried?

You already have the format. Use aa for AM/PM.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Is your input already a timestamp or is it coming in as a string?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Sgiri1
Participant
Posts: 43
Joined: Sat Nov 08, 2008 10:58 pm
Location: Tambaram

Post by Sgiri1 »

The i/p is a string and the o/p is a timestamp
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Then use StringToTimestamp() with a mask the matches your input format. What you show as 'required output' isn't really true if you are targeting a Timestamp but might be if you were a string.

Or perhaps "timestamp_from_string", depends on the stage you are doing this in. I believe that's the Modify stage conversion function, the former would be used in a Transformer.
-craig

"You can never have too many knives" -- Logan Nine Fingers
dxk9
Participant
Posts: 105
Joined: Wed Aug 19, 2009 12:46 am
Location: Chennai, Tamil Nadu

Post by dxk9 »

You can use Stringtotimestamp() function in the transformer stage for the conversion.

Ideally it will be something like:

StringToTimestamp(<input data>,"%yyyy/%mm/%dd %hh:%nn:%ss")

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

Post by chulett »

Dashes, not slashes.
-craig

"You can never have too many knives" -- Logan Nine Fingers
dxk9
Participant
Posts: 105
Joined: Wed Aug 19, 2009 12:46 am
Location: Chennai, Tamil Nadu

Post by dxk9 »

The required o/p is "mm/dd/yyyy hh:mi:ss AM " format. So slashes only will solve the issue.

If there is still problem with the output data or if you get any error w.r.t conversion while running, let me know. There are few changes to be done w.r.t the job properties for Timestamp conversions. But that is necessary only if you come across any error.

Regards,
Divya
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

dxk9 wrote:The required o/p is "mm/dd/yyyy hh:mi:ss AM " format. So slashes only will solve the issue.
Have you tried it?

StringToTimestamp requires the Mask for input string not the output. So you need to match that mask with your input string which consists of dashes. Look for page number 191 in parallel job advanced developer guide.

Craig, you are correct.

format in which it will be converted is (by default)
%yyyy-%mm-%dd %hh:%mm:%ss (Page 192)

OP,
Now why you want to change the format of a timestamp. If writing to a flat file then convert it to string once again to get the required format.

If writing to a database, it will be stored in internal format anyways. And all I can guess is "you have a display problem and not a conversion problem".

In case of Display problem check/change the format defined in NLS settings in database or use to_char() or equivalent function to change your display.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
Post Reply