Page 1 of 1

need to convert string(DDMMYYYY) to Date field YYYY-MM-DD

Posted: Thu Dec 09, 2010 4:45 am
by mac4rfree85
Hi Guys,

I am getting Data from source in a flat file. There is a column D_DATE which will have data in the format DDMMYYYY. I need to convert it to YYYY-MM-DD. I used StringToDate function but in vain.
The Code i used are

Code: Select all

StringToDate(DSLink1.D_DATE,"%yyyy%mm%dd")
as well as

Code: Select all

StringToDate(DSLink1.D_DATE,"yyyy-mm-dd")
first one is giving me a output full of "*" , second one is throwing an error.

Can somebody let me know where i am going wrong.

Thanks for your help in advance.

Re: need to convert string(DDMMYYYY) to Date field YYYY-MM-D

Posted: Thu Dec 09, 2010 4:48 am
by bgs_vb
Hi,
In StringTodate function you should specify incoming date format not desired date format i.e StringToDate(datefield,"%dd%mm%yyyy") if you source adte is in ddmmyyyy format .

Re: need to convert string(DDMMYYYY) to Date field YYYY-MM-D

Posted: Thu Dec 09, 2010 5:40 am
by Harini

Code: Select all

DateToString(StringToDate(DSLink1.D_DATE,"%dd%mm%yyyy"), "%yyyy-%mm-%dd")

Posted: Thu Dec 09, 2010 6:51 am
by mac4rfree85
thanks guys,, that solved my problem.. but the data coming from the source is coming in two formats..

1. 20102009
2. 20-10-2009

Can you please advise me what needs to be done. i do not want to drop any of the records..
THanks once again for your help...

Posted: Thu Dec 09, 2010 8:17 am
by Harini
Remove the '-'s from your Date, if the date contains '-'s in a stage variable, and then call it in the Derivation.

Posted: Thu Dec 09, 2010 8:32 am
by Ravi.K
Use Convert function to remove "-".

DateToString(StringToDate(Convert('-','',DSLink1.D_DATE),"%dd%mm%yyyy"), "%yyyy-%mm-%dd")

Posted: Thu Dec 09, 2010 1:47 pm
by mac4rfree85
Thanks Guys,, that solves my problem ... Thanks all for your help...