string to timestamp with AM/PM

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
rameshkm
Participant
Posts: 24
Joined: Tue May 06, 2008 6:02 am
Location: chennai
Contact:

string to timestamp with AM/PM

Post by rameshkm »

Hi,

I have a string value as "Jan 22 2010 2:12:44:201PM", i want to convert this string value to timestamp like 2010-01-22 14:12:44:201, is there any short way to handle this ? mean minimum using of stage variable.

Thanks
Ramesh Kumar.M
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

Is the :201 portion of the time supposed to be milliseconds? Assuming so:

Convert to a timestamp by using StringToTimestamp() with a format specifier of "%mmm %d %yyyy %H:%n:%s:%SSS%aa"

When you're ready to output to a text field, or a flat file, use TimestampToString() with a format specifier of "%yyyy-%mm-%dd %hh:%nn:%ss:%SSS"

You may have to play around with the format specifiers a little bit...they are documented in the Parallel Job Developer Guide.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
rameshkm
Participant
Posts: 24
Joined: Tue May 06, 2008 6:02 am
Location: chennai
Contact:

Thank you so much

Post by rameshkm »

I will try it and let you know.
Ramesh Kumar.M
rameshkm
Participant
Posts: 24
Joined: Tue May 06, 2008 6:02 am
Location: chennai
Contact:

Re: Thank you so much

Post by rameshkm »

Hi

Please find the error below, while i tried to use your approach

--------------------------------------------------------------------------------
XFR_In_Trans_1,0: Caught exception from runLocally(): APT_ParseError: Parsing parameters "%mmm %d %yyyy %H:%n%s:%(SSS,v)%aa" for conversion "timestamp=timestamp_from_string[%yyyy-%mm-%dd %hh:%nn:%ss](string)": APT_Conversion_String_TimeStamp: Invalid format [%mmm %d %yyyy %H:%n%s:%(SSS,v)%aa] used for string_from_time type conversion.
--------------------------------------------------------------------------------

Please help in this, whether I have change any default Timestamp String format ?
Ramesh Kumar.M
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

You're missing the colon between %n and %s in the time portion of the format string. For some reason, the format validator doesn't like it.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
rameshkm
Participant
Posts: 24
Joined: Tue May 06, 2008 6:02 am
Location: chennai
Contact:

Thank you my Friend

Post by rameshkm »

Hi Friend,

Its working fine , i used the below format to achive this

StringToTimestamp(Column1,"%mmm %(d,s) %yyyy %(H,s):%n:%s:%SSS%(aa,w)")

, thank you so much, i never forget this great help
Ramesh Kumar.M
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Re: Thank you my Friend

Post by vamsi.4a6 »

Could anyone explain description about following format specifiers?

1)%(d,s)
2)%(H,s)
3)%(aa,w)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

vamsi.4a6 wrote:Could anyone explain description about following format specifiers?
jwiles wrote:You may have to play around with the format specifiers a little bit...they are documented in the Parallel Job Developer Guide.
Oddly enough, in a section titled "Date and time formats". :wink:
-craig

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