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.
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...
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...
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?
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!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now