Add 1 year to given date

nate100

Member
I need to get 1 year from the current year.
For example, if date = 9/9/08 then 1 year more would be 9/9/09.

I want to know the best way to get this. I can use the YEAR function and strip out the year and then add 1 year and then recreate the new date but looking for something simpler.

Thanks
 
If you are using a sufficiently modern version of Progress, look up the ADD-INTERVAL function. If you aren't using a sufficiently modern version, you now have yet another reason to upgrade.
 
we can add 365 to the variable.

define variable i as date.
i = 09/09/08.
disp i with frame a.
i = i + 365.
disp i with frame b.


But this cannot be correct if the year is leap year.
 
I need to get 1 year from the current year.
For example, if date = 9/9/08 then 1 year more would be 9/9/09.

I want to know the best way to get this. I can use the YEAR function and strip out the year and then add 1 year and then recreate the new date but looking for something simpler.

Thanks

Surely this isn't too hard?

lvNewDate = DATE(MONTH(lvOldDate),DAY(lvOldDate),YEAR(lvOldDate) + 1).
 
Surely this isn't too hard?

lvNewDate = DATE(MONTH(lvOldDate),DAY(lvOldDate),YEAR(lvOldDate) + 1).

That will fail if lvOldDate is Feb 29...

If you are on an old, obsolete and effectively unsupported release that does not support the DateTime datatype then you need code similar to this:

Code:
define variable oldDate as date no-undo.
define variable newDate as date no-undo.

update oldDate with side-labels.

if month( oldDate ) = 2 and day( oldDate ) = 29 then
  newDate = date( 3, 1, year( oldDate ) + 1 ).
 else
  newDate = date( month( oldDate ), day( oldDate ), year( oldDate ) + 1 ).

display newDate.
 
Bah always those stupid leap years... thanks for pointing out the error of my ways.
 
Back
Top