Converting M/DD/YYYY to YYYY-MM-DD

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
paranoid
Premium Member
Premium Member
Posts: 185
Joined: Tue May 29, 2007 5:50 am

Converting M/DD/YYYY to YYYY-MM-DD

Post by paranoid »

Hi,

I need to convert a date format from M/DD/YYYY to YYYY-MM-DD. Is there any easy way of doing it in datastage?

Eg: If my input date is 7/15/2000, output should be 2000-15-07

If input date is 7/7/2000, output should be 2000-07-07

Thanking you in advance...

sue
wahi80
Participant
Posts: 214
Joined: Thu Feb 07, 2008 4:37 pm

Re: Converting M/DD/YYYY to YYYY-MM-DD

Post by wahi80 »

Hi,

For DS Server version use iconv and oconv functions to convert date to different formats
For syntax check the forum or the pdf

Regards
Wah
Abburi
Participant
Posts: 31
Joined: Tue May 29, 2007 12:38 pm

Re: Converting M/DD/YYYY to YYYY-MM-DD

Post by Abburi »

Hi,

You can Use Iconv and Oconv Functions as :

Trim(Oconv(Iconv(LinkName.DateColumn,"D-YMD[4,2,2]"),"DYMD[4,2,2]")," ","A")

This will give you the desired output. "InputDate" is the date in
YYYY-MM-DD Format.
Regards,
Abburi
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

Oconv(Iconv(InLink.TheDate, "DMDY"), "D-YMD[4,2,2]")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
paranoid
Premium Member
Premium Member
Posts: 185
Joined: Tue May 29, 2007 5:50 am

Post by paranoid »

Hi,

Thank you very much for your replies.

I got the desired output using the following function:

oconv(iconv(InputDate,"D4/MDY[2,2,4]") , "D4-YMD[4,2,2]")



Thanks

Sue
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Hmmm... while it may work, the 4 in "D4" isn't needed and (as noted in the documentation) the 'modifiers' of '[2,2,4]' and the delimiter are for output only and are ignored on input. So, suprisingly, all that was needed was exactly what Ray posted. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Surprisingly???
:roll:
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 »

Did you not see Mr Winkie? I had originally written 'not surprisingly' but in a moment of insanity decided to remove the not and have some fun. :wink: :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
paranoid
Premium Member
Premium Member
Posts: 185
Joined: Tue May 29, 2007 5:50 am

Post by paranoid »

Hi,

Thank you for your replies.Even without '4' it is working.Is there any specific use of using '4' in it?

Thanks

Sue
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The syntax of the 'D' conversion code is fully documented in the online help. From the help Index, type a "D" and that should take you right to D code [BASIC] where the syntax is explained along with a number of examples.

You can also get there from the OConv or IConv topics.
-craig

"You can never have too many knives" -- Logan Nine Fingers
paranoid
Premium Member
Premium Member
Posts: 185
Joined: Tue May 29, 2007 5:50 am

Post by paranoid »

Hey,

I got it!! Thanks once again!!


Sue
Post Reply