Year child will become 18.

Community Beginner ,
Nov 14, 2017

Copy link to clipboard

Copied

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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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...

TOPICS
Acrobat SDK and JavaScript, Windows

Views

95

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Year child will become 18.

Community Beginner ,
Nov 14, 2017

Copy link to clipboard

Copied

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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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...

TOPICS
Acrobat SDK and JavaScript, Windows

Views

96

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 14, 2017 0
Most Valuable Participant ,
Nov 14, 2017

Copy link to clipboard

Copied

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...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 14, 2017 0
Community Beginner ,
Nov 14, 2017

Copy link to clipboard

Copied

That's great, thank you so much.

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 14, 2017 0
Angus24 LATEST
Community Beginner ,
Nov 14, 2017

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 14, 2017 0