Date conversion

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
Willo
Participant
Posts: 10
Joined: Fri Jan 02, 2004 2:07 am

Date conversion

Post by Willo »

Hi,

I'm having a problem with dates, I have a date in the format of:

yyyy-mm-dd 00:00:00

I need to convert it into the follwoing format:

dd/mm/yyyy 00:00:00

Can anyone help me?? These date conversions are driving me crazy!!!

Thanks

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

Post by chulett »

Iconv and Oconv are your friends and are usually used together. If you search in this forum for them, you'll see there are a ton of posts discussing date formatting issues and resolutions.

Code: Select all

Oconv(Iconv(field_name,"D-YMD[4,2,2]"),"D/DMY[2,2,4]"
This should get you started but will need to be modified to handle the time portion. The Status function can be used to check for success of either conversion.

You can also check out the Date routines in your 'sdk' folder for examples of using these functions.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Willo
Participant
Posts: 10
Joined: Fri Jan 02, 2004 2:07 am

Post by Willo »

chulett,

Thanks for your reply, the timestamp is real issue I'm having, I can convert yyyy-mm-dd but I don't know what to do about the timestamp element.

I've looked at the SDK but it only converts to internal and not extrenal.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Well, if the time portion is always zero you could cheat. :shock: :lol: Convert the Date and then append a zero time string at the end of it.

If you want to do it right, use the FIELD command to break the string up into its Date and Time portions. Convert the Date and then stick the time back on the end afterwards. Make this reusable by writing a Routine to do this.

That help?
-craig

"You can never have too many knives" -- Logan Nine Fingers
davidthree
Participant
Posts: 11
Joined: Fri Nov 07, 2003 11:14 am

Post by davidthree »

As an alternative to using the inner/outer conversion functions, why not just process the date using string manipulation:

Code: Select all

MyDate[9,2]:'/':MyDate[6,2]:'/':MyDate[1,4]:MyDate[11,9]
should perform the conversion you require.

Although this might be slow (?)

David
jreddy
Premium Member
Premium Member
Posts: 202
Joined: Tue Feb 03, 2004 5:09 pm

Post by jreddy »

Hi,

I guess this is pretty long piece of derivation, but it gets the job done..

Oconv(Iconv(field(<linkname.columnname>, " ", 1, 1), "D-YMD[4,2,2]"), "D/DMY[2,2,4]"):" ":field(<linkname.columnname>, " ", 2, 3)

if you need to get it written into oracle table, then i would suggest you prefix this with
DateTimeStampToOraOCIWithTime(DateGenericToTimeStamp(<piece of code shown above>))

Hope this helps you..it worked for me
Willo
Participant
Posts: 10
Joined: Fri Jan 02, 2004 2:07 am

Post by Willo »

Cheers guys that code works, I was tempted by chulett's suggestion of trimming the timestamp but that would be cheating!!
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Willo wrote:Cheers guys that code works, I was tempted by chulett's suggestion of trimming the timestamp but that would be cheating!!
It's not cheating, since DataStage is a "data type free environment".
And it may be quicker!
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