Date format

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
dspxlearn
Premium Member
Premium Member
Posts: 291
Joined: Sat Sep 10, 2005 1:26 am

Date format

Post 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.
Thanks and Regards!!
dspxlearn
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sbass1
Premium Member
Premium Member
Posts: 211
Joined: Wed Jan 28, 2009 9:00 pm
Location: Sydney, Australia

Re: Date format

Post 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]")
Some people are the Michael Jordan's of Datastage. I'm more like Muggsy Bogues :-)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sbass1
Premium Member
Premium Member
Posts: 211
Joined: Wed Jan 28, 2009 9:00 pm
Location: Sydney, Australia

Post by sbass1 »

Doh! Sorry for the misinformation...
Some people are the Michael Jordan's of Datastage. I'm more like Muggsy Bogues :-)
dspxlearn
Premium Member
Premium Member
Posts: 291
Joined: Sat Sep 10, 2005 1:26 am

Post by dspxlearn »

I used the string formatting instead of the conversions.
Thanks!!
Thanks and Regards!!
dspxlearn
Post Reply