How do I add 2 years to a date in powerbuilder and account for the leap year correctly?

Judy picture Judy · Jan 5, 2010 · Viewed 12.1k times · Source

How do I add 2 years to a date in powerbuilder and account for the leap year correctly?

We have a medical license application where the user would like the date to go expire two years. Current license date is 7/10/2010 and expire date should be 7/2/2012 I used relative date and added 729 if not a leap year and 730 if it was but that is messy.

I wish the relativedate function took another parameter to so you could pass in number years.

Answer

Terry picture Terry · Jan 6, 2010

How about:

// adjusted from suggestions
IF Month (ldt_OldDate) = 2 AND Day (ldt_OldDate) = 29 THEN
   ldt_NewDate = Date (Year(ldt_OldDate) + 2, 3, 1) 
   // or ... 2, 28) whichever you think is two years from Feb 29
ELSE
   ldt_NewDate = Date (Year(ldt_OldDate) + 2, Month (ldt_OldDate), Day (ldt_OldDate))
END IF

Good luck,

Terry