Page 1 of 1

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

Posted: Wed Jan 27, 2016 4:20 pm
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

Posted: Wed Jan 27, 2016 4:59 pm
by just4u_sharath
stringtodate(DSLink9.DT,"%m/%d/%yyyy") this worked

Posted: Wed Jan 27, 2016 5:07 pm
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.

Posted: Wed Jan 27, 2016 5:44 pm
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.