Skip to main content
Known Participant
November 14, 2017
Answered

Year child will become 18.

  • November 14, 2017
  • 3 replies
  • 543 views

I’m working in Acrobat Pro and I have a field named ChildDOB, date format is m/d/yyyy.

I have a second field named Date18.

I need to figure out when the child will turn 18. The statement that I am working with is this:

If the child is under the age of 18 they must meet the criteria stated in Section 1. Date the child will become age 18: ___________.

I know I need to add 18 years to the child’s date of birth, but not sure how to achieve this.

Help is much appreciated.

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer try67

You can use this code as the custom calculation script of your field:

var dobString = this.getField("ChildDOB").valueAsString;

if (dobString=="") event.value = "";

else {

    var dob = util.scand("m/d/yyyy", dobString);

    event.value = dob.getFullYear()+18;

}

Edit: fixed a typo in the code...

3 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 14, 2017

You can use this code as the custom calculation script of your field:

var dobString = this.getField("ChildDOB").valueAsString;

if (dobString=="") event.value = "";

else {

    var dob = util.scand("m/d/yyyy", dobString);

    event.value = dob.getFullYear()+18;

}

Edit: fixed a typo in the code...

Angus24Author
Known Participant
November 14, 2017

That's great, thank you so much.

Is there a way to incorporate the birth month and day along with the year?

Angus24Author
Known Participant
November 14, 2017

I was able to come up with the coding that would provide the birth month and day with the new year (18 years into the future). Here is the coding:

var dobString = this.getField("ChildDOB").valueAsString; 

if (dobString=="") event.value = ""; 

else { 

    var dob = util.scand("m/d/yyyy", dobString); 

   dob.setYear(dob.getFullYear()+18);                // new line of code

    event.value = util.printd("m/d/yyyy", dob);     //new line of code

} 

Thank you try67 for setting me on the right path with your coding, I greatly appreciate it!