Adding a date

Hi,

How can we add some 5 years to a particular date, say today. So i want to have a date which is 5 years from today…

Tried adding to date, but it added to only the days.

Can anyone help me out!!

Thanks
Sriram

Not a very elegant or sofisticated solution but as far as I can see it works :wink:
Except: the technique below doesn’t handle “feb 29”!

DEFINE DATA LOCAL
1 D (D)
1 A (A10)
1 REDEFINE A
2 YYYY (N4)
END-DEFINE
MOVE *DATX TO D
MOVE EDITED D (EM=YYYYMMDD) TO A
ADD 5 TO YYYY
MOVE EDITED A TO D (EM=YYYYMMDD)
DISPLAY D
END

To get the same day in the next year, you can code:

add 366 to #date

The problem is: In case of an included leap day, you have to code:

add 367 to #date

But maybe you can combine this with the leap year test discussed here: http://tech.forums.softwareag.com/viewtopic.php?t=7298

Hi Sriam
I’ve improved my algorithm to take care of leap year and made it into a subprogram.
Finn


  • Subprogram to add a number of years to a date
  • Finn the Dane - July 2007
    DEFINE DATA PARAMETER
    1 IN-PARMS
    2 IN-DATE (D)
    2 IN-ADD-YEARS (I2)
    1 OUT-DATE (D)
    LOCAL
    1 A (A10)
    1 REDEFINE A
    2 YYYY (N4)
    2 MM (N2)
    2 DD (N2)
    END-DEFINE

MOVE EDITED IN-DATE (EM=YYYYMMDD) TO A
ADD IN-ADD-YEARS TO YYYY
IF NOT (A IS (D)) /* Test for leap year
MOVE 3 TO MM /* and move to 1st of March if new year is not a leap year
MOVE 1 TO DD
END-IF
MOVE EDITED A TO OUT-DATE (EM=YYYYMMDD)
END