Automatically Calculate Age from a Birth Date in Adobe Acrobat Forms
Question details
Calculate a person's age automatically in a PDF form using an entered birth date.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A form user enters a birth date, and the Age field should calculate the person's current age.
- Observed behavior
- The Age field should update when the form recalculates and account for whether the birthday has occurred this year.
Open the PDF in Adobe Acrobat and confirm that you can edit its form fields. Decide on a birth-date format and check that Acrobat JavaScript is enabled in Preferences.
Add an age calculation script to the Acrobat form
Use a custom calculation on the Age field to calculate full years from a birth date entered as MM/DD/YYYY.
Open the PDF in Adobe Acrobat and select All tools > Prepare a form. Add two text fields if they do not already exist.
Open each field's Properties and set the birth-date field name to BirthDate and the result field name to Age. In the BirthDate field's Format tab, select Date and the MM/DD/YYYY format.
Open the Age field's Properties, select Calculate > Custom calculation script, and click Edit. Paste this script and save it: var raw = this.getField("BirthDate").valueAsString; var match = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(raw); event.value = ""; if (match) { var month = Number(match[1]); var day = Number(match[2]); var year = Number(match[3]); var birth = new Date(0); birth.setFullYear(year, month - 1, day); birth.setHours(0, 0, 0, 0); var today = new Date(); if (year > 0 && birth.getFullYear() === year && birth.getMonth() === month - 1 && birth.getDate() === day && birth <= today) { var age = today.getFullYear() - year; if (today.getMonth() < month - 1 || (today.getMonth() === month - 1 && today.getDate() < day)) { age--; } event.value = age; } }
Save the PDF, exit Prepare a form, and enter a birth date in BirthDate. Test dates before and after today's month and day in Acrobat or Adobe Reader; the Age field should show the corresponding age.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its Microsoft Office format compatibility helps you move existing files into your workflow. It does not fix Acrobat's JavaScript settings or guarantee support for Acrobat form scripts.

Frequently Asked Questions
Why is the Age field blank after I enter a date?
Enter a valid, nonfuture date as MM/DD/YYYY and check that the birth-date field is named BirthDate. In Age Properties > Calculate, confirm that the custom script is saved.
Where do I enable JavaScript in Acrobat?
Open Acrobat Preferences, select JavaScript, and check that Acrobat JavaScript is enabled. Reopen the form and test the date field again.
Will the age update automatically on the person's birthday?
The script uses the current device date when the form recalculates. It does not necessarily run at midnight, so the form may need another field change or recalculation to refresh the age.
Can I use different field names?
Yes. If you rename the birth-date field in Prepare a form, replace BirthDate in this.getField("BirthDate") with the exact new field name. Place the script in the Calculate tab of the field that should display the age.




