CONVERT 'MM-DD-YYYY' to 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
praburaj
Premium Member
Premium Member
Posts: 133
Joined: Thu Jun 30, 2005 1:26 am
Location: philippines

CONVERT 'MM-DD-YYYY' to YYYY-MM-DD

Post by praburaj »

My source file having one date column. It has value like Ex: '02/03/2001'. I need to load my date column like yyyy-mm-dd. I don't know how to remove the single code from the date value. Plz help me to achieve this Issue?

Input :'01/02/2001'
Output:2001-02-01
prabakaran.v
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You need a combination of StringToDate() and DateToString() functions each with an appropriate format string.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Assuming you really need that output format... what is your target datatype for this? String or Date?
-craig

"You can never have too many knives" -- Logan Nine Fingers
praburaj
Premium Member
Premium Member
Posts: 133
Joined: Thu Jun 30, 2005 1:26 am
Location: philippines

Post by praburaj »

chulett wrote:Assuming you really need that output format... what is your target datatype for this? String or Date? ...
Thanks for your response chulett. My Target data type is date. I tried even convert function to remove first single quote from the file like this. Convert ('''','',inputcolumn). But no luck.
prabakaran.v
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

I would suggest this as your transformer derivation. note that the first argument of Convert is "'"--double quote, single quote, double quote:

Code: Select all

StringToDate(Convert("'", "", inputcolumn),"%mm/%dd/%yyyy")
Or when you import the column from your source, you can specify that the column is a quoted varchar or char, with single quotes. This would remove the quotes for you when imported.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Date data types don't have a format, so all you need to do (assuming the source is a text file) is StringToDate() function.

James suggests that you eliminate single quotes from the source data - a good idea if they're there.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
manoj_23sakthi
Participant
Posts: 47
Joined: Tue Feb 23, 2010 12:16 am
Location: CHENNAI

Post by manoj_23sakthi »

Hi
You may extract the source file by using sequential file??
If you using the sequential file we have Format Tab in sequential file
date/ Format string we can occur this .... or else better go by using transformer Below mentioned replies
synsog
Premium Member
Premium Member
Posts: 232
Joined: Sun Aug 01, 2010 11:01 pm
Location: Pune

Re: CONVERT 'MM-DD-YYYY' to YYYY-MM-DD

Post by synsog »

For removing quotes, while reading from source file itself, for the column, in column properties, give quote as 'single'. then the sequential file will read the date column without the single quote.
Post Reply