Page 1 of 1

Date format

Posted: Thu May 07, 2009 9:42 am
by dspxlearn
Hi,


I need to convert the '04/01/2009' date in string format to '4/1/2009'.
Basically, i need to trim out the leading zeros using Trim functions.

Code: Select all

My code:
Trim('04/01/2009'[1,2], '0','L') :'-' : Trim('04/01/2009'[4,2], '0','L') :'-': Right('04/01/2009',2)
Output will be 4/1/09.

Instead of using this lengthy code can we convert the source string to date and then back to string to get just as '4/1/09'. Or please let me know if there is any other way.

Posted: Thu May 07, 2009 4:53 pm
by ray.wurlod
Conversion to and from date would do it, but it will be far more complex than your substring-based solution. You need appropriate format strings in each case. What happens when day or month needs two digits?

Re: Date format

Posted: Thu May 07, 2009 8:45 pm
by sbass1
dspxlearn wrote:Hi,


I need to convert the '04/01/2009' date in string format to '4/1/2009'.
Basically, i need to trim out the leading zeros using Trim functions.

Code: Select all

My code:
Trim('04/01/2009'[1,2], '0','L') :'-' : Trim('04/01/2009'[4,2], '0','L') :'-': Right('04/01/2009',2)
Output will be 4/1/09.

Instead of using this lengthy code can we convert the source string to date and then back to string to get just as '4/1/09'. Or please let me know if there is any other way.
Does this do what you want?

Code: Select all

Ans = oconv(iconv(Arg1,"DMDY[2,2,4]"),"DMDY/[1,1,4]")

Posted: Thu May 07, 2009 9:48 pm
by ray.wurlod
sbass1 wrote:Does this do what you want?

Code: Select all

Ans = oconv(iconv(Arg1,"DMDY[2,2,4]"),"DMDY/[1,1,4]") 
Not in a parallel Transformer stage. Iconv() and Oconv() are not supported.

Posted: Thu May 07, 2009 11:46 pm
by sbass1
Doh! Sorry for the misinformation...

Posted: Fri May 08, 2009 12:37 am
by dspxlearn
I used the string formatting instead of the conversions.
Thanks!!