Date convertion

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
markus
Participant
Posts: 6
Joined: Fri Feb 24, 2006 1:50 pm
Location: germany

Date convertion

Post by markus »

Hi All,

I have date in '19960422' format and I need to convert it in '04/22/1996'.

Thanks,
markus
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

welcome aboard Markus,
DS has ICONV/OCONV functions. If you go to help and read about those functions, you will see that they provide a variety of conversions.
Even one that supports your needs
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
srimitta
Premium Member
Premium Member
Posts: 187
Joined: Sun Apr 04, 2004 7:50 pm

Post by srimitta »

Do substring an concatinate in derivation

'19960422' [5,2]:'/':'19960422' [7,2]:'/':'19960422' [1,4] = '04/22/1996'
diamondabhi
Premium Member
Premium Member
Posts: 108
Joined: Sat Feb 05, 2005 6:52 pm
Location: US

Post by diamondabhi »

What srimitta says is a good answer but also use trim befor u use a substring, instead i would use iconv and oconv.
vsi
Premium Member
Premium Member
Posts: 507
Joined: Wed Mar 15, 2006 1:44 pm

Re: Date convertion

Post by vsi »

markus wrote:Hi All,

I have date in '19960422' format and I need to convert it in '04/22/1996'.

Thanks,
markus

hi all,
how to use iconv and oconv converting dates
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

use this

Code: Select all

Oconv(Iconv(in.date,"DYMD[4,2,2]"),"D/MDY[2,2,4]")
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ogmios
Participant
Posts: 659
Joined: Tue Mar 11, 2003 3:40 pm

Re: Date convertion

Post by ogmios »

Try the following, should be pretty close to what you want:

Code: Select all

Oconv(Iconv(%Arg1%,  "D4YMD[4,2,2]"), "D/")
Ogmios
In theory there's no difference between theory and practice. In practice there is.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Markus, in case you are confused, the plethora of answers results from the fact that DataStage server edition does not have data type restrictions. So some of the answers use substring and concatenation techniques (OK if you can guarantee that your dates are always YYYYMMDD format), others use date conversion functions Iconv() and Oconv() which allow for some flexibility in handling dates (for example dates with only two digit year). I would use

Code: Select all

Oconv(Iconv(InLink.TheDate, "DYMD"), "D/MDY[2,2,4]")
"DYMD" asserts that the incoming date is in year-month-day order but nothing more. "D/MDY[4,2,2]" very specifically states that the output date (string) will be in month day year order with exactly two digits for month and day, and exactly four digits for year.
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