Page 1 of 1

Converting Date format from YYYY-MM-DD to YYYYMMDD

Posted: Thu Nov 29, 2007 5:37 am
by Christina
Hi,

My source is a Date datatype in YYYY-MM-DD format.
How can i convert it to Date(8) in YYYYMMDD format?

Posted: Thu Nov 29, 2007 5:52 am
by siva4joy
you can use convert function to remove '-'.
syntax for the function is Convert('-','', Input_Date_Column)
and you can use substring function ,and syntax is
Input_Date_Column[1,4]:Input_Date_Column[6,2]:Input_Date_Column[8,2]

Posted: Thu Nov 29, 2007 6:16 am
by Christina
Will this give the output as date dataype with length 8?

Posted: Thu Nov 29, 2007 8:01 am
by siva4joy
no the output will be string

Converting Date format from YYYY-MM-DD to YYYYMMDD

Posted: Thu Nov 29, 2007 8:13 am
by Christina
I want the output to be in Date with length 8.

Please provide a solution....

Posted: Thu Nov 29, 2007 8:40 am
by chulett
StringToDate() with the appropriate format mask. Forget about the 'to YYYYMMDD' part, a date is a date.

Posted: Thu Nov 29, 2007 8:49 am
by DSguru2B
No conversion is required. Just change the date output format in the extended properties of the field.

Posted: Thu Nov 29, 2007 9:39 am
by Christina
How to change the extended properties of the field?
I am new to DataStage PX.

I tried the following, but got some error.

StringToDate(Convert('-','',Date_Column),"%yyyy%mm%dd")

Error: Failure during execution of operator logic
Conversion error calling conversion routine date_from_string
data may have been lost

Posted: Thu Nov 29, 2007 10:46 am
by ZDC
Hi there,
As DSGuru suggested ...
Just go to
format tab>type defaults and then go for the date ,
change the format string to %yyyy%mm%dd in the output tab,it will work for sequential file as i have done this in past.No need to worry about datatype.



Cheers,
ZDC

Hi

Posted: Thu Nov 29, 2007 10:56 am
by neena
As shiva4joy said i tested converting yyyy-mm-dd to yyyymmdd using sequential file and in transformer i used convertion string , convert('-','', inputlink_columnname)and changed length properties of datecolumn in column tab in target to 8 and it worked fine. But i did in server job.

Posted: Thu Nov 29, 2007 11:59 am
by prasson_ibm
Christina wrote:How to change the extended properties of the field?
I am new to DataStage PX.

I tried the following, but got some error.

StringToDate(Convert('-','',Date_Column),"%yyyy%mm%dd")

Error: Failure during execution of operator logic
Conversion error calling conversion routine date_from_string
data may have been lost

hi, it can be simpaly done by Oconv(Iconv(INPUT_LINK,"D-YMD"),"YMD")............ :)

Posted: Thu Nov 29, 2007 1:14 pm
by DSguru2B
Guys, server solutions will not work in px. Follow ZDC's suggestion. He basically explained what I said earlier.

Converting Date format from YYYY-MM-DD to YYYYMMDD

Posted: Thu Nov 29, 2007 10:35 pm
by Christina
Thanks a lot guys...

The solution given by DSguru2B and ZDC works...