Function in datastage to find date after 6 months
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 3
- Joined: Mon Jun 04, 2007 1:28 am
- Location: India
Function in datastage to find date after 6 months
Is there any date function in datastage server to find out the date of the specified months ...like for eg what will be date after 6 months or what was the date before 6 months as of todays date
Yes, this can be done using the ICONV() and OCONV() functions. First, use ICONV() to convert your date into then internal format, which is an integer number of days since Dec 31, 1967. Once you have this internal format you have various options, for instance adding or subtracting 182 days and then converting it back to a display date using OCONV(). Or you can use one of the ICONV() functions to get the day & month and can then just add 6 months yet keep the same day. It all depends upon what you define as "6 months".
-
- Participant
- Posts: 3
- Joined: Mon Jun 04, 2007 1:28 am
- Location: India
Thanks Sachin and ArndW for your suggestion But what i need is how to implement the add_months in datastage server.
So i what to write a routine say addmonth(X, Arg1) where x is number of months and Arg1 is a date and it should return date x months after the date in argument 1 of the routine taking into account the leap year.
X can take any integer value say 5,123 ect
So i what to write a routine say addmonth(X, Arg1) where x is number of months and Arg1 is a date and it should return date x months after the date in argument 1 of the routine taking into account the leap year.
X can take any integer value say 5,123 ect
Lets assume your date is in the format YYYYMMDD and is passed into your routine as "InDate" and your second parameter is "AddMonths" which is a value between -12 and 12.
Code: Select all
OutYear = InDate[1,4]
OutMonth = InDate[5,2]
OutDay = InDate[7,2]
OutMonth += AddMonths
IF (OutMonth>12) THEN
OutYear += 1
OutMonth -= 12
END
Ans = OutYear:OutMonth:OutDay
I forgot to add those lines, thanks for reminding me, Craig.
TestDate = ICONV(Ans,'D4YMD')
Result = @STATUS
BEGIN CASE
CASE Result = 3
CALL DSLogWarn('Oh No, Mr. Bill! The computed date "':Ans:'" has been converted to "':OCONV(Ans,'D4/YMD'):'".,'MyProgram')
CASE Result = 1
CALL DSLogWarn('The computed date "':Ans:'" is invalid.','MyProgram')
END CASE
TestDate = ICONV(Ans,'D4YMD')
Result = @STATUS
BEGIN CASE
CASE Result = 3
CALL DSLogWarn('Oh No, Mr. Bill! The computed date "':Ans:'" has been converted to "':OCONV(Ans,'D4/YMD'):'".,'MyProgram')
CASE Result = 1
CALL DSLogWarn('The computed date "':Ans:'" is invalid.','MyProgram')
END CASE
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
From what I recall, you could also use OConv to automatically 'adjust' a date that has overflowed a month, if that works for your requirements. For example, adding six months to 08/31/2007 gives you 2/31/2008. If turning that into 3/2/2008 is the answer rather than 'rewinding' back to 2/29, that can be done as well.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers