Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Script Help - Add to Date


Level 2

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)


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.

1 Reply


Level 2

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.