Script Help - Add to Date

Avatar

Avatar

MHaywood323

Avatar

MHaywood323

MHaywood323

14-04-2015

Need a little FormCalc OR JavaScript Help from the Community.

Have a form that has three fields ...  Date Of Birth, Age, and Emancipation Date.

User Selects DOB, then I calculate Age: (Works Fine)

if(DOB.rawValue ne null) then

     Floor(((Date2Num(DOB.formattedValue, "MM/DD/YYYY") - Date() )/365.25)*-1)

endif

The Emancipation Date Field is the one I need some help with.

I need to Have that field Calculate the Date the person turns 18 if Age < 18

I think the easiest way is just to add "18" to the YYYY part instead of calculating it due to leap years and such.

Any Suggestions would be very helpful.

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar

MHaywood323

Avatar

MHaywood323

MHaywood323

15-04-2015

So, A solution I found, but not sure it is the best came from this thread: Re: how to calculate future date

var Emancipation = new Date(DOB.formattedValue);

var Adult = new Date(new Date(Emancipation).setMonth(Emancipation.getMonth()+216));

util.printd("mm/dd/yyyy", Adult);

I am using setMonth  to +216 for 18 years ...

It seems to work in all my tests unless there is a better solution.