Date conversion from 1/1/2014 to 2014-01-01

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
just4u_sharath
Premium Member
Premium Member
Posts: 236
Joined: Sun Apr 01, 2007 7:41 am
Location: Michigan

Date conversion from 1/1/2014 to 2014-01-01

Post by just4u_sharath »

Hello,
I am trying to convert 1/1/2014 to 2014-01-01. Any suggestions. I tried this but output to file has all ***

DatetoString(stringtodate(DSLink9.DT,"%mm/%dd/%yyyy"),"%yyyy-%mm-%dd")

Thanks
just4u_sharath
Premium Member
Premium Member
Posts: 236
Joined: Sun Apr 01, 2007 7:41 am
Location: Michigan

Post by just4u_sharath »

stringtodate(DSLink9.DT,"%m/%d/%yyyy") this worked
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Probably didn't really "work work" as "2014-01-01" isn't a date but rather a string. So what you posted as working would be fine if the actual target data type is a DATE (which is why you only would need the format for the input string) or the original post would be close to what you would need to convert from one string to another using those two different formats.

You'll also find it will work for "1/1/2014" but not "01/01/2014" or "10/1/2014) but perhaps that's not a concern in your specific scenario.
-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 »

Format string "%m/%d/%yyyy" is not a good general solution. It's OK if you are only dealing with the first day of the month, but fails when the number of digits in the day or month reaches two.

Search DSXchange or review the documentation for a format string that will handle one- or two-digit date components.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply