Calculate a Date Two Years Later in an Adobe Acrobat PDF Form
Question details
Automatically display a date two years after a date entered in another PDF form field.

- 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.
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.
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.
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.
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.
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 = ""; } }
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.

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.

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.




