Page 1 of 1
ROUTINES
Posted: Fri May 13, 2005 8:13 pm
by sainath
HI
i am new to datastage.I want to know how to write routine for following
situation
expiry date( in timestamp) = effective date - 1.i tried using iconv and oconv but i am not able to get result.
thanks
sai
Posted: Sat May 14, 2005 8:03 am
by ArndW
Sainath,
ICONV and OCONV will do what you tell them to. If I understand your question correctly, you want to write a function that returns a timestamp (I'll assume that you want YYYY-MM-DD HH:MM:SS) using either the current date.
Function MySampleRoutine(Unused)
Ans = OCONV(@DATE-1,'D-YMD[4,2,2]'):' ':OCONV(@TIME,'MTS')
Return(Ans)
(The green colored text comes from the DS function design)
This is a 1-liner which can be done directly in a transform variable or a derivation.
Is this what you were asking?
Posted: Sat May 14, 2005 5:40 pm
by ray.wurlod
Almost but not quite. I suspect EffectiveDate is an input value, so needs to be the Routine argument. If it's an external-format date it will need an ICONV applied to it before the arithmetic. If it's a timestamp it will need decomposition into date and time components.
Code: Select all
FUNCTION ExpiryDate(EffectiveDate)
* Effective date is a Timestamp: decompose into date and time
EffDate = Field(EffectiveDate, " ", 1, 1)
EffTime = Field(EffectiveDate, " ", 2, 1)
* Convert date component into internal format
IntDate = Iconv(EffDate, "DYMD")
* Calculate date component of expiry date (business logic)
NewDate = IntDate - 1
* Convert that date into external format
ExpDate = Oconv(NewDate, "D-YMD[4,2,2]")
* Construct timestamp to return to caller
Ans = ExpDate : " " : EffTime
RETURN(Ans)
Routine
Posted: Sun May 15, 2005 11:05 am
by sainath
Hi
I agree with ray that since the input date is timestamp first i have to use
ICONV then OCONV.Thank you very much for ray and Arwd for quick reply.
sai