String to timestamp conversion

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

satishm
Participant
Posts: 22
Joined: Wed Aug 20, 2008 6:37 am

String to timestamp conversion

Post by satishm »

Hi Friends,
Need a help on date time stamp conversion.

I recieve a timestamp of format which will be read in a CFF stage using cobol definition :
2009091909.25.03 am (yyyymmddhh.mm.ss am) - 12 hours format.
Bytes:19
Data type: Character

Now I want to convert it in to standard date time stamp 2009-09-19 09.25.03
I used coversion format string to timestamp in transformer stage but it outputed strange (***************)


Appreciate your help.

Regards,
Satish.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Could you provide the exact derivation that you used? With the exact input and output datatype.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
satishm
Participant
Posts: 22
Joined: Wed Aug 20, 2008 6:37 am

Post by satishm »

kumar_s wrote:Could you provide the exact derivation that you used? With the exact input and output datatype. ...
Hi Kumar,

Please find the exact derivation and datatype of input and output respectively

StringToTimestamp(DSLink4.time,"%yyyy-%mm-%dd %hh:%nn:%ss")


Input:
19 bytes Char

Output:
26 Bytes, scale 0f 6 Timestamp

Regards,
Satish
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

It doesn't match the input data format.
Strip out 'AM' part of the data (last two character) and providet value as "%yyyy%mm%dd%hh.%mm.%ss"
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
neena
Participant
Posts: 90
Joined: Mon Mar 31, 2003 4:32 pm

Post by neena »

When you bring the field try to change into "yyyy-mm-dd hh:nn:ss" format and use the function. I did a test job and it seems like the function is working only with the above format.
satishm
Participant
Posts: 22
Joined: Wed Aug 20, 2008 6:37 am

Post by satishm »

neena wrote:When you bring the field try to change into "yyyy-mm-dd hh:nn:ss" format and use the function. I did a test job and it seems like the function is working only with the above format.
Neena,
Will you please share your derivation.
And how about if date time stamp is 'pm' ?
neena
Participant
Posts: 90
Joined: Mon Mar 31, 2003 4:32 pm

Post by neena »

you need to add more logic when it is PM. Like create a stage variable to check for PM and hour part.

Like

Stage vari: When string = 'PM' and hour part = '12' Then '12' Else If string = 'PM' Then '12+hour part[]' Else hour part
neena
Participant
Posts: 90
Joined: Mon Mar 31, 2003 4:32 pm

Post by neena »

Stage Var1: String[18,2]

Stage Var2: When Stage Var2 = 'PM' and string[9,2] = '12' Then '12' Else If Stage Var2 = 'PM' Then '12+string[9,2]' Else string[9,2]

Stage var3: String[1,4]:'-':string[5,2]:'-':string[7,2]: ' ':Stage Var2: String[11,6]

Column derivarion: StringToTimestamp(Stage var3,"%yyyy-%mm-%dd %hh:%nn:%ss")

Replace string with your field name.
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post by Kryt0n »

The format you provide to StringToTimestamp needs to match your input format, not how you want it to look.

For am/pm use the %aa format option

Help files are more than enough to figure out the correct format
satishm
Participant
Posts: 22
Joined: Wed Aug 20, 2008 6:37 am

Post by satishm »

Kryt0n wrote:The format you provide to StringToTimestamp needs to match your input format, not how you want it to look.

For am/pm use the %aa format option

Help files are more than enough to figure out the correct format
Thanks, Neena ...It worked.....God BlesS!!
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So you quoted the simple solution but actually implemented an unnecessarily complex one? If so, you might want to revisit this. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
satishm
Participant
Posts: 22
Joined: Wed Aug 20, 2008 6:37 am

Post by satishm »

chulett wrote:So you quoted the simple solution but actually implemented an unnecessarily complex one? If so, you might want to revisit this. :wink: ...
Sorry...I dint get u
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What solution did you use - all that extra work using stage variables or the proper StringToTimestamp function syntax that Kryt0n helped out with?
-craig

"You can never have too many knives" -- Logan Nine Fingers
satishm
Participant
Posts: 22
Joined: Wed Aug 20, 2008 6:37 am

Post by satishm »

chulett wrote:What solution did you use - all that extra work using stage variables or the proper StringToTimestamp function syntax that Kryt0n helped out with? ...
One which Neena provided, as i dont wanna store am/pm in table and also wanna store it in 24 hrs format..
She provided a perfect solution.

But thanks to all for all the help.
satishm
Participant
Posts: 22
Joined: Wed Aug 20, 2008 6:37 am

Post by satishm »

satishm wrote:
chulett wrote:What solution did you use - all that extra work using stage variables or the proper StringToTimestamp function syntax that Kryt0n helped out with? ...
One which Neena provided, as i dont wanna store am/pm in table and also wanna store it in 24 hrs format..
She provided a perfect solution.

But thanks to all for all the help.

Ran the job using

StringToTimestamp(DSLink4.time,"%yyyy%mm%dd %hh.%nn.%ss %aa")

got aborted with following error
APT_CombinedOperatorController,0: Unrecognized timestamp format identifier: %97
APT_CombinedOperatorController,0: Caught exception from runLocally(): APT_ParseError: Parsing parameters "%yyyy%mm%dd %hh.%nn.%ss %aa" for conversion "timestamp=timestamp_from_string[%yyyy-%mm-%dd %hh:%nn:%ss](string)": APT_Conversion_String_TimeStamp: Invalid Format [%yyyy%mm%dd %hh.%nn.%ss %aa] used for string_from_time type conversion.
Operator signalled one or more errors.
Post Reply