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

Post Reply
kool78
Participant
Posts: 104
Joined: Sat Aug 20, 2005 2:02 pm

String to Timestamp Conversion

Post by kool78 »

HI GURUS,

i have a job where i need to load a csv file into Oracle table..

one of the columns has the following data in the below format:

6/7/2007 19:00
10/11/2007 19:00
11/8/2007 19:00
12/6/2007 19:00
1/10/2008 19:00
2/7/2008 19:00
6/28/2007 19:00
7/12/2007 19:00
7/26/2007 19:00
5/31/2007 19:00
6/7/2007 19:00
6/14/2007 19:00
6/21/2007 19:00
6/28/2007 19:00
7/5/2007 19:00


i have to lad this string into oracle table whose column is a timestamp. i tried it in different ways..but couldnt get eh perfect solution for string to timestamp conversion..

can anyone throw some light or provide help on this.

appreciate any kind of information..
thanks
"Attitude always and almost determines the altitude of your Life"
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You need to work on two things:
1) Check the length of day and month, if its one then prefix it with a zero.
2) Append :00 as seconds to the end.

Then pass it to StringToTimestamp() with the mask of %mm/%dd/%yyyy %hh:%nn:%ss.
Last edited by DSguru2B on Thu Jun 07, 2007 9:43 am, edited 1 time in total.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
battaliou
Participant
Posts: 155
Joined: Mon Feb 24, 2003 7:28 am
Location: London
Contact:

Post by battaliou »

Ja, check this link out. There's plenty of info on timestamps.

viewtopic.php?t=95920&postdays=0&postor ... mp&start=0
3NF: Every non-key attribute must provide a fact about the key, the whole key, and nothing but the key. So help me Codd.
kool78
Participant
Posts: 104
Joined: Sat Aug 20, 2005 2:02 pm

Post by kool78 »

DSguru2B wrote:You need to work on two things:
1) Check the length of day and month, if its one then prefix it with a zero.
2) Append :00 as seconds to the end.

Then pass it to StringToTimestamp() with the mask of %mm/%dd/%yyyy %hh:%nn:%ss.
HI

I was able to convert the date part as

StringToDate(right('0':Field(DSLink41.WW_DATE,'/',1), 2):'/':right('0':Field(DSLink41.WW_DATE,'/',2), 2):'/':Field(DSLink41.WW_DATE,'/',3),"%mm/%dd/%yyyy")

but im not able to get the logice on how to get the timestamp part :

any help on the code ?

thanks
"Attitude always and almost determines the altitude of your Life"
kool78
Participant
Posts: 104
Joined: Sat Aug 20, 2005 2:02 pm

Post by kool78 »

more details of how the column value looks like at the source side

06/07/2007 7:00:00 PM
10/11/2007 7:00:00 PM
11/08/2007 7:00:00 PM
12/06/2007 7:00:00 PM

unable to convert this to timestamp...

any help or code is appreciated.

thanks
"Attitude always and almost determines the altitude of your Life"
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You need to check if day and month are single digit and only then prefix it with zero.
Specify stage variables to fix the day and month

Code: Select all

StgMonth-        If Len(Field(in.Date, "/", 1)) = 1 then "0":in.Date else in.Date
StgDay -         If Len(Field(StgMonth, "/", 2)) = 1 then Field(StgMonth, "/", 
                 1):"/0":StgMonth[4,20] else StgMonth
Now for the derivation. Use StgDay in your StringToTimestamp().
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kool78
Participant
Posts: 104
Joined: Sat Aug 20, 2005 2:02 pm

Post by kool78 »

DSguru2B wrote:You need to check if day and month are single digit and only then prefix it with zero.
Specify stage variables to fix the day and month

Code: Select all

StgMonth-        If Len(Field(in.Date, "/", 1)) = 1 then "0":in.Date else in.Date
StgDay -         If Len(Field(StgMonth, "/", 2)) = 1 then Field(StgMonth, "/", 
                 1):"/0":StgMonth[4,20] else StgMonth
Now for the derivation. Use StgDay in your StringToTimestamp().

hey DSGURU2B,

thanks for your quick responses

when i se the data in csv file it appears as like this :
12/13/2007 19:00
12/20/2007 19:00
12/27/2007 19:00
1/3/2008 19:00
1/10/2008 19:00
1/17/2008 19:00
1/24/2008 19:00
1/31/2008 19:00
2/7/2008 19:00


and the same data when i read it thru a sequential file stage it appears as like this :

12/13/2007 7:00:00 PM
12/20/2007 7:00:00 PM
01/03/2008 7:00:00 PM


wht should i understand from this...im unable to convert this string format to timestamp.

any light on this
"Attitude always and almost determines the altitude of your Life"
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

How are you reading it as? Is it varchar? If thats the case then you dont need to do any month or day check. Just send it to StringToTimestamp() with the mask I gave you in my first post. It should work.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kool78
Participant
Posts: 104
Joined: Sat Aug 20, 2005 2:02 pm

Post by kool78 »

DSguru2B wrote:How are you reading it as? Is it varchar? If thats the case then you dont need to do any month or day check. Just send it to StringToTimestamp() with the mask I gave you in my first post. It should work.

hi i did that....

im reading it as varchar and then in transformer i did the stringtotimestamp conversion but its aborting,

since the format is in this way for ex: 06/12/2007 7:00:00 PM,,i think its not taking the time format in this..

any help on this
"Attitude always and almost determines the altitude of your Life"
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

You are reading it as varchar in transformer but after using StringtoTimestamp you make sure that it should come out from transformer as timestamp SQL type.
hi sam here
kool78
Participant
Posts: 104
Joined: Sat Aug 20, 2005 2:02 pm

Post by kool78 »

samsuf2002 wrote:You are reading it as varchar in transformer but after using StringtoTimestamp you make sure that it should come out from transformer as timestamp SQL type.
yes i did that.....

the traget column metadata is timestamp:

but how do you reperesent the format for this kind of data

"6/23/2007 7:00:00 PM"

i mean what format you would privde?
"Attitude always and almost determines the altitude of your Life"
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

Format should be "%mm/%dd/%yyyy %hh:%mm:%ss"
hi sam here
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

A small correction. Its "%mm/%dd/%yyyy %hh:%nn:%ss (without any space in the time mask.)
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 »

Ya thats right !

Thanks DSGuru
hi sam here
Post Reply