Converting Date format from YYYY-MM-DD to YYYYMMDD

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
Christina
Participant
Posts: 34
Joined: Wed Sep 06, 2006 11:50 am

Converting Date format from YYYY-MM-DD to YYYYMMDD

Post 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?
siva4joy
Premium Member
Premium Member
Posts: 34
Joined: Fri Apr 14, 2006 6:10 am
Location: London

Post 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]
Thanks and Regards,
Sivasankar.z
+44-07807478984
Christina
Participant
Posts: 34
Joined: Wed Sep 06, 2006 11:50 am

Post by Christina »

Will this give the output as date dataype with length 8?
siva4joy
Premium Member
Premium Member
Posts: 34
Joined: Fri Apr 14, 2006 6:10 am
Location: London

Post by siva4joy »

no the output will be string
Thanks and Regards,
Sivasankar.z
+44-07807478984
Christina
Participant
Posts: 34
Joined: Wed Sep 06, 2006 11:50 am

Converting Date format from YYYY-MM-DD to YYYYMMDD

Post by Christina »

I want the output to be in Date with length 8.

Please provide a solution....
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

StringToDate() with the appropriate format mask. Forget about the 'to YYYYMMDD' part, a date is a date.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

No conversion is required. Just change the date output format in the extended properties of the field.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Christina
Participant
Posts: 34
Joined: Wed Sep 06, 2006 11:50 am

Post 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
ZDC
Premium Member
Premium Member
Posts: 15
Joined: Fri Nov 23, 2007 5:06 am

Post 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
Zero Degree Consulting
neena
Participant
Posts: 90
Joined: Mon Mar 31, 2003 4:32 pm

Hi

Post 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.
prasson_ibm
Premium Member
Premium Member
Posts: 536
Joined: Thu Oct 11, 2007 1:48 am
Location: Bangalore

Post 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")............ :)
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Guys, server solutions will not work in px. Follow ZDC's suggestion. He basically explained what I said earlier.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Christina
Participant
Posts: 34
Joined: Wed Sep 06, 2006 11:50 am

Converting Date format from YYYY-MM-DD to YYYYMMDD

Post by Christina »

Thanks a lot guys...

The solution given by DSguru2B and ZDC works...
Post Reply