hallo all,
I would like to manipulate a date field.
My date value is YYYYMMDD.
I would like to get the next 6 months from the date.
For example :
Original Date : 20030303
New Date : 20030903
Original Date : 20030703
New Date : 20040103
Am I supposed to convert to internal date for the manipulation?
Or are there any built-in transform or routines that I can use to achieve these?
Would so much appreciate your advice for the solution.
thanz and Regards,
Christina
Increment Date Field by 6 months
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 74
- Joined: Tue Sep 30, 2003 4:25 am
- Location: Malaysia
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
You can add 183 days to the internal format, or use substrings to add six months to the date. The latter would need to be done in a routine.
I leave it as an exercise to add code to handle a negative second argument.
Code: Select all
FUNCTION AddMonthsToDate(BaseDate, Months)
Equate RoutineName To "AddMonthsToDate"
Ans = @NULL
Test = Iconv(BaseDate, "DYMD")
If Status() = 0 And BaseDate Matches "8N" Then
If Months Matches "1N0N" : @VM : "'+'1N0N"
Then
Year = BaseDate[1,4]
Month = BaseDate[5,2]
Day = BaseDate[7,2]
Month += 6
If Month > 12
Then
Month -= 12
Year += 1
End
Ans = Fmt(Year,"R%4") : Fmt(Month("R%2") : Day
End
Else
Call DSTransformError("Non-integer months in Arg2.", RoutineName)
End
End
Else
Call DSTransformError("Invalid date " : Quote(BaseDate), RoutineName)
End
RETURN(Ans)
Last edited by ray.wurlod on Fri Jul 02, 2004 4:31 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 74
- Joined: Tue Sep 30, 2003 4:25 am
- Location: Malaysia
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Participant
- Posts: 74
- Joined: Tue Sep 30, 2003 4:25 am
- Location: Malaysia