time stamp 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

pradeepleon
Participant
Posts: 32
Joined: Fri Dec 02, 2005 10:44 pm
Location: Chicago,IL

Re: time stamp conversion

Post by pradeepleon »

Check for the OCONV() function in the help topics.
Thanks,
Pradeep

(Ten Hugs And Nine KisseS - THANKS)......is that true?

In GOD we trust,for all others we take cash.
sud
Premium Member
Premium Member
Posts: 366
Joined: Fri Dec 02, 2005 5:00 am
Location: Here I Am

Re: time stamp conversion

Post by sud »

pradeepleon wrote:Check for the OCONV() function in the help topics.
Parallel jobs, no oconv. Well, you have to actually check this, the timestamp format within datastage IS in 24 hr format, so you should not have to do anything special.
It took me fifteen years to discover I had no talent for ETL, but I couldn't give it up because by that time I was too famous.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There is no Oconv() function in the parallel Transformer stage.

Convert the timestamp to a string, and substring off the am/pm designator (Right() function is ideal).
Substring out the hours field, convert to int8 and, if the designator is PM add 12. Convert back to string.
Use concatenation to reassemble the parts, then convert back to timestamp.

Use stage variables for intermediate results - it will make future maintenance much easier.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
pradeepleon
Participant
Posts: 32
Joined: Fri Dec 02, 2005 10:44 pm
Location: Chicago,IL

Re: time stamp conversion

Post by pradeepleon »

sud wrote:
pradeepleon wrote:Check for the OCONV() function in the help topics.
Parallel jobs, no oconv. Well, you have to actually check this, the timestamp format within datastage IS in 24 hr format, so you should not have to do anything special.
Oh I'm sorry, I thought it to be for a server job.
Thanks,
Pradeep

(Ten Hugs And Nine KisseS - THANKS)......is that true?

In GOD we trust,for all others we take cash.
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

THANKS TO ALL . That field is coming as char (26) , can any one please tell me what function i can use for this condition .
hi sam here
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Use the following in Modify stage.

Code: Select all

date_fmt:timestamp = timestamp_from_string [%mmm %dd %yyyy %hh:%nn:%ss]  (date_tst) 
But in order for this to work, you will have to pre process your date to have two digits for day.
To get the scale of 3, in your target stage, set the default timestamp format to %yyyy-%mm-%dd %hh:%nn:%ss.6
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

I have around 5 time stamp fields where should i specify their names in the code provided. i want to keep the same field name .

Thanks
hi sam here
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

O yea, forgot to mention that.
date_fmt is your source column name and
date_tst is your target column name. They can be same too, I think.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

i am new to modify stage , i gave 5 specification with that code and changed the format to %yyyy-%mm-%dd %hh:%nn:%ss.6 , i am getting this error

Un-handled conversion error on field "UMIT_STS_DTM " from source type "string[26]" to destination type "timestamp":
source value="Jul 9 1998 12:01:51:346PM"; the result is non-nullable and there is no handle_null to specify a default value

how do i pre process that date to have two digits for day?
hi sam here
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

If you are comfortable with the transformer then you can preprocess the date in a stage variable to get two digit day. Something like the following:

Specify a stage variable, say FixDay. Its derivation will be

Code: Select all

If Len(Field(in.Col, " ", 2)) = 1 then Field(in.Col, " ", 1):' 0':Field(in.Col, " ", 2,3) else in.Col
Now in the derivation use

Code: Select all

StringToTimestamp(FixDay, "%mmm %dd %yyyy %hh:%nn:%ss")
Now your target is not nullable. Hence you need to wrap the last derivation into NullToValue() and provide an appropriate value if null is encountered.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

when i am trying to run by using the above code its giving me this warning

Transformer_6,0: Conversion error calling conversion routine timestamp_from_string data may have been lost

and data is coming as all *s , my date is like this

"Jul 6 1998 12:00:00:000AM" after Jul there are 2 spaces.
hi sam here
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Do you have two spaces between the Month and Day in all your date fields or just a few?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

if the date is Jul 7 ----it has 2 spaces
if the date is Jul 12 -----it has 1 space , i am testing this with seq --transformer---seq.

later i can add modify stage ,what data type should i use for the above job char ot time stamp?
hi sam here
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

Read it as varchar from source stage. Have you tried DSGuru's routine ?
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Ok, then change the FixDay stage variable's derivation to the following:

Code: Select all

If in.Col[5,1] = " " then in.Col[1,3]:" 0":in.Col[6,21] else in.Col
The StringToTimestamp() derivation will remain the same. Read the date as varchar.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply