Page 1 of 1

Date convertion

Posted: Thu Apr 13, 2006 10:42 am
by markus
Hi All,

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

Thanks,
markus

Posted: Thu Apr 13, 2006 10:44 am
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

Posted: Thu Apr 13, 2006 10:51 am
by srimitta
Do substring an concatinate in derivation

'19960422' [5,2]:'/':'19960422' [7,2]:'/':'19960422' [1,4] = '04/22/1996'

Posted: Thu Apr 13, 2006 10:54 am
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.

Re: Date convertion

Posted: Thu Apr 13, 2006 11:01 am
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

Posted: Thu Apr 13, 2006 11:03 am
by DSguru2B
use this

Code: Select all

Oconv(Iconv(in.date,"DYMD[4,2,2]"),"D/MDY[2,2,4]")

Re: Date convertion

Posted: Thu Apr 13, 2006 11:04 am
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

Posted: Thu Apr 13, 2006 4:03 pm
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.