3 Replies Latest reply on Nov 14, 2017 3:37 PM by Angus24

    Year child will become 18.

    Angus24 Level 1

      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.

       

        • 1. Re: Year child will become 18.
          try67 MVP & Adobe Community Professional

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

          • 2. Re: Year child will become 18.
            Angus24 Level 1

            That's great, thank you so much.

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

            • 3. Re: Year child will become 18.
              Angus24 Level 1

              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!