Char to Timestamp

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

rockr
Participant
Posts: 17
Joined: Thu Feb 01, 2007 3:56 pm

Char to Timestamp

Post by rockr »

Hi everyone,

I have a job where I get the input as char and I have the data in this format "19500101".

I used the modify stage to convert this column to timestamp, I used the specification as "NEWCOL:timestamp = timestamp_from_string (INPUTCOL)" . I get the output as "NULL" in the target dataset. Am I doing something worng here ?.

I need the output as timestamp to write to a Oracle stage. is there anyway I can convert it ?

Thanks for reading !
sud
Premium Member
Premium Member
Posts: 366
Joined: Fri Dec 02, 2005 5:00 am
Location: Here I Am

Re: Char to Timestamp

Post by sud »

You are getting null since the input is not in default format i.e., "%yyyy-%mm-%dd hh:nn:ss". Put a format string and it should work.
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.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You are not giving the mask of the input format. Else the engine will not know what is the format date that you are trying to convert.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
rockr
Participant
Posts: 17
Joined: Thu Feb 01, 2007 3:56 pm

Post by rockr »

(NEWCOL:timestamp)= timestamp_from_string(OUTCOL,%yyyy%mm%dd) is this correct ?
Last edited by rockr on Fri Feb 08, 2008 10:35 am, edited 1 time in total.
sud
Premium Member
Premium Member
Posts: 366
Joined: Fri Dec 02, 2005 5:00 am
Location: Here I Am

Post by sud »

Code: Select all

NEWCOL:timestamp= timestamp_from_string[%yyyy%mm%dd](OUTCOL)
I wonder if you need an actual time component in the input, if this does not work, try converting to date and then date to timestamp.
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.
rockr
Participant
Posts: 17
Joined: Thu Feb 01, 2007 3:56 pm

Post by rockr »

It dose not work, Can I convert Char to dat and Date to timestamp as you said in a single modify stage ?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

The Modify stage allows only one action to be done per column.
rockr
Participant
Posts: 17
Joined: Thu Feb 01, 2007 3:56 pm

Post by rockr »

How do I use
StringToTimestamp(%string%,[%"%yyyy-%mm-%dd %hh:%nn:%ss"%]) Function in the transformer ?


The part in the RED is supposed to the format of the input string or the output string. I suppose its the INPUT format, So if my format is "20010101" am i supposed to use "%yyyy%mm%dd"
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Correct.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
rockr
Participant
Posts: 17
Joined: Thu Feb 01, 2007 3:56 pm

Post by rockr »

ok,

I am using StringToTimestamp(INPUTCOL,"yyyymmdd") and my input is 20070101

This is my FATAL ERROR log

APT_CombinedOperatorController,0: Caught exception from runLocally(): APT_ParseError: Parsing parameters "yyyymmdd" for conversion "timestamp=timestamp_from_string[%yyyy-%mm-%dd %hh:%nn:%ss](string)": APT_Conversion_String_TimeStamp: Invalid Format [yyyymmdd] used for string_from_time type conversion.


Please point out if I might have done something wrong?
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

yyyymmdd is not the same as %yyyy%mm%dd
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What happened to the %s?
-craig

"You can never have too many knives" -- Logan Nine Fingers
rockr
Participant
Posts: 17
Joined: Thu Feb 01, 2007 3:56 pm

Post by rockr »

Same ERROR when I use "%yyyy%mm%dd" :(

APT_CombinedOperatorController,0: Caught exception from runLocally(): APT_ParseError: Parsing parameters "%yyyy%mm%dd" for conversion "timestamp=timestamp_from_string[%yyyy-%mm-%dd %hh:%nn:%ss](string)": APT_Conversion_String_TimeStamp: Invalid Format [%yyyy%mm%dd] used for string_from_time type conversion.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Try the following

Code: Select all

StringToTimestamp(TRIM(INPUTCOL):"000000","%yyyy%mm%dd%hh%nn%ss") 
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
rockr
Participant
Posts: 17
Joined: Thu Feb 01, 2007 3:56 pm

Post by rockr »

But my input data is "20010101", shouldnt I mention the mask for the Input data ?
Post Reply