Skip to main content
Participating Frequently
December 16, 2022
Answered

if - then: 2 different dates to calculate age

  • December 16, 2022
  • 1 reply
  • 6063 views

I would like to calculate someone's age based upon whether a "permission" date is entered. If no permission date is entered in the "Permission" field, then the age is calculated on today's date and is displayed in the "Age" field (where I am writing the code). If a permission date is entered in the "Permission" field, then the age is calculated using the date entered in the "Permission" field and is displayed in the "Age" field. If not too much trouble, I would like the age to display as years & months (example: 11-10). Thank you in advance for help!!! Dave

This topic has been closed for replies.
Correct answer bebarth

I did run into 1 small issue. Even when I delete/clear both the permission date and the date of birth, the "Student Age" and "Less than 12" fields retain the results from when previously calculated? I can certainly live with this small issue by waiting until I enter another student's information in the same place, but if there is a quick fix, that would be better? Thanks again!


Sorry for the delay!

I just added 2 lines at the end of the script for resetting the fields when the date of birth is empty, but that worked fine for me with the "Clear Form" button.

Please use this new file and let me know.

@+

1 reply

Thom Parker
Community Expert
Community Expert
December 17, 2022

Have you looked at all the other posts on calculating age?  There must be hundreds. 

 

Here's one that provides an age calc for the current date. It's a good place to start. 

https://community.adobe.com/t5/acrobat-discussions/calculating-age-based-dob-and-today-s-date/m-p/12789562

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
December 18, 2022

I have looked at many of the available posts. I do not have enough knowledge about code to piece things together from different posts so they will work for my project. For now, instead of leaving the "Permission" field blank, I will just enter "today's date" into "Permission" field until I have permission to evaluate the child, then change the date in the "Permission" field to the date permission was granted. Regarding displaying age in years and months: For now, I will have the "Age" field just display in years (11) instead of years & months (11-10). Simple and less automated will be better until I have time to learn more about code.

Thanks for your suggestion...

bebarth
Community Expert
Community Expert
December 19, 2022

I do see java scripting of some sort when I right click on the "page". It may be important to point out that there are 40 students per page where these calculations are taking place.


As you have 40 studients, you certainly have fields with indices, so the script will be a bit different!

Could you share a file and I'll show you how do that...

@+