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

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
mac4rfree85
Participant
Posts: 126
Joined: Thu Jul 01, 2010 11:39 pm

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

Post 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.
Mac4rfree
bgs_vb
Premium Member
Premium Member
Posts: 79
Joined: Mon Jan 02, 2006 5:51 am

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

Post 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 .
Harini
Premium Member
Premium Member
Posts: 80
Joined: Tue Mar 16, 2010 1:32 am

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

Post by Harini »

Code: Select all

DateToString(StringToDate(DSLink1.D_DATE,"%dd%mm%yyyy"), "%yyyy-%mm-%dd")
mac4rfree85
Participant
Posts: 126
Joined: Thu Jul 01, 2010 11:39 pm

Post 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...
Mac4rfree
Harini
Premium Member
Premium Member
Posts: 80
Joined: Tue Mar 16, 2010 1:32 am

Post by Harini »

Remove the '-'s from your Date, if the date contains '-'s in a stage variable, and then call it in the Derivation.
Ravi.K
Participant
Posts: 209
Joined: Sat Nov 20, 2010 11:33 pm
Location: Bangalore

Post by Ravi.K »

Use Convert function to remove "-".

DateToString(StringToDate(Convert('-','',DSLink1.D_DATE),"%dd%mm%yyyy"), "%yyyy-%mm-%dd")
Cheers
Ravi K
mac4rfree85
Participant
Posts: 126
Joined: Thu Jul 01, 2010 11:39 pm

Post by mac4rfree85 »

Thanks Guys,, that solves my problem ... Thanks all for your help...
Mac4rfree
Post Reply