PDF Editing Issues

Calculate a Date Two Years Later in an Adobe Acrobat PDF Form

Khadija KhanKhadija Khan Nov 19, 2026 868 views

Question details

Automatically display a date two years after a date entered in another PDF form field.

Calculate a Date Two Years Later in an Adobe Acrobat PDF Form
Product
Adobe Acrobat PDF forms
Device & OS
not provided
Scenario
A PDF form has a source date field formatted as dd/mm/yy and needs a second field to calculate a date two years later.
Observed behavior
The destination field should update when the source date changes and remain blank when no source date is entered.
Before you start

Open the form in Adobe Acrobat with access to the Prepare a Form tool, and identify the names of the source and destination fields. The completed form must be opened in a PDF viewer that supports Acrobat JavaScript for the automatic calculation to run.

Solution 1Recommended

Add a custom calculation script to the destination date field

Use this method to update the second field automatically whenever the source date is committed or changed.

1
Check the field names

In Acrobat, open All tools > Prepare a form. Open each field's Properties and check its name on the General tab. The script below assumes the source field is named A; replace A with your actual source field name.

2
Set the source date format

In the source field's Properties, open Format, select Date, and choose dd/mm/yy or enter that format if the available options allow it.

3
Add the calculation

Open the destination field's Properties, select Calculate > Custom calculation script, and click Edit. Enter: var s = this.getField("A").valueAsString; if (s === "") { event.value = ""; } else { try { var d = util.scand("dd/mm/yy", s); d.setFullYear(d.getFullYear() + 2); event.value = util.printd("dd/mm/yy", d); } catch (e) { event.value = ""; } }

4
Save and test the form

Save the PDF, then enter a date in field A and move to another field. Confirm that the destination shows the date two years later. Clear field A and confirm that the destination also clears.

Add a custom calculation script to the destination date field
Leap days and two-digit years: JavaScript's setFullYear rolls February 29 to March 1 when the target year is not a leap year. Use a four-digit year format such as dd/mm/yyyy if the century must be unambiguous.
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 format compatibility makes it easy to bring existing files into your workflow. Use Acrobat to create and test the PDF JavaScript calculation described above; WPS is not a replacement for that scripting step.

Open and work with PDF documents alongside Office filesCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for a straightforward transition from OfficeFree, lightweight workspace for everyday document tasks
microsoft office alternative - wps office

Frequently Asked Questions

Why is the calculated date blank?

In Prepare a Form, check that the source field name matches the name in this.getField("A") and that the entered date matches dd/mm/yy. Also check that Acrobat JavaScript is enabled and that the viewer supports PDF form calculations.

Will this calculation work in a browser PDF viewer?

Not necessarily. Browser PDF viewers may not support Acrobat JavaScript. Open the saved form in Adobe Acrobat or Reader and test the calculation there.

What happens if the source date is February 29?

The script uses setFullYear. If the year two years later is not a leap year, JavaScript rolls February 29 forward to March 1.

How can I use a four-digit year instead?

In the source field's Format properties, choose or enter dd/mm/yyyy. Change both dd/mm/yy strings in the calculation script to dd/mm/yyyy, then test the form again.