Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Year child will become 18.

Community Beginner ,
Nov 14, 2017 Nov 14, 2017

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.

TOPICS
Acrobat SDK and JavaScript , Windows
473
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 14, 2017 Nov 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...

Translate
Community Expert ,
Nov 14, 2017 Nov 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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 14, 2017 Nov 14, 2017

That's great, thank you so much.

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 14, 2017 Nov 14, 2017
LATEST

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!

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