converting a string to Date

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
bhasannew
Participant
Posts: 31
Joined: Wed Aug 06, 2008 10:54 pm

converting a string to Date

Post by bhasannew »

Hi,

Is there any way to convert a string (dd-mm-yyyy) to date format. I think it is possible to convert a string which is in the format 'yyyy-mm-dd' to date easily using type conversion functions, but i need to convert the above string which is in the format 'dd-mm-yyyy' to date.

For ex: '23-06-1999' (datatype: String ) ===> '1999-06-23' (datatype: Date)

Is there any way to handle this? I wrote a routine to do that, but the thing is it is taking much time to process the records. Using stage variables also i tried handling it by splitting and concatenating the separated bits, even that one proved to be not an optimised solution.

Can you please through light on this.

thanks,
Bhasan.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Of course. The StringToDate() function takes the format of the incoming string so just get that right and convert any valid date.
-craig

"You can never have too many knives" -- Logan Nine Fingers
dsuser_cai
Premium Member
Premium Member
Posts: 151
Joined: Fri Feb 13, 2009 4:19 pm

Post by dsuser_cai »

you can use the StringTodate function in the transformer

StringToDate(Column_name,"%dd-%mm-%yyyy")
Thanks
Karthick
bhasannew
Participant
Posts: 31
Joined: Wed Aug 06, 2008 10:54 pm

Post by bhasannew »

Thank you all for the inputs.

i wonder if the format is like this 'dd-mon-yy' (for eg: '02-mar-09') then how to convert it into valid date?

I tried using StringtoDate(Column_name,'dd-mon-yy'). It is not converting properly.

Thanks in advance,

bhasan.
gssr
Participant
Posts: 243
Joined: Fri Jan 09, 2009 12:51 am
Location: India

Post by gssr »

Try this,

Code: Select all

StringToDate(Column_name,"%dd-%mmm-%yy") 
RAJ
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Not quite.

The Date And Time Formats are fully documented in the Parallel Job Developer Guide pdf.
-craig

"You can never have too many knives" -- Logan Nine Fingers
bhasannew
Participant
Posts: 31
Joined: Wed Aug 06, 2008 10:54 pm

Post by bhasannew »

Thank you All.

the issue got resolved with the following

StringToDate(Column_name,'dd-mmm-yy')

-Bhasan
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Hopefully, what you meant to type was:

Code: Select all

StringToDate(Column_name,'%dd-%mmm-%yy')
Also be mindful of the century pivot when you use two-digit years.
-craig

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