PDF Editing Issues

Automatically Calculate Age from a Birth Date in Adobe Acrobat Forms

Maira MehtabMaira Mehtab Nov 18, 2026 870 views

Question details

Calculate a person's age automatically in a PDF form using an entered birth date.

Automatically Calculate Age from a Birth Date in Adobe Acrobat Forms
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the form editor

Open the PDF in Adobe Acrobat and select All tools > Prepare a form. Add two text fields if they do not already exist.

2
Name the fields

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.

3
Add the calculation

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; } }

4
Save and test

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.

Add an age calculation script to the Acrobat form
Calculation behavior: The script uses the device's current date and runs when the form recalculates; it does not guarantee an update at midnight. Invalid or future dates leave Age blank. For a February 29 birth date, it treats March 1 as the birthday in non-leap years.
Free Microsoft Office alternative

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.

Open and review PDF forms in a familiar workspaceCompatible with Microsoft Office formats including DOCX, XLSX, and PPTXFree tools for common document tasksLightweight interface for an easier transition from Office
microsoft office alternative - wps office

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.