Page 1 of 1

converting a string to Date

Posted: Mon Feb 15, 2010 9:29 am
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.

Posted: Mon Feb 15, 2010 9:44 am
by chulett
Of course. The StringToDate() function takes the format of the incoming string so just get that right and convert any valid date.

Posted: Mon Feb 15, 2010 1:37 pm
by dsuser_cai
you can use the StringTodate function in the transformer

StringToDate(Column_name,"%dd-%mm-%yyyy")

Posted: Tue Feb 16, 2010 1:13 am
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.

Posted: Tue Feb 16, 2010 1:22 am
by gssr
Try this,

Code: Select all

StringToDate(Column_name,"%dd-%mmm-%yy") 

Posted: Tue Feb 16, 2010 6:37 am
by chulett
Not quite.

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

Posted: Tue Feb 16, 2010 7:14 am
by bhasannew
Thank you All.

the issue got resolved with the following

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

-Bhasan

Posted: Tue Feb 16, 2010 8:29 am
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.