Calculate a PDF Form Date 1,096 Days After the Later Date
Question details
Calculate Date3 as 1,096 days after the later of Date1 and Date2 in a PDF form.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A form needs to compare two entered dates and automatically populate a third date.
- Observed behavior
- Date3 should display the date 1,096 days after the later input date.
Open the form in a PDF editor that supports Acrobat form JavaScript, such as Adobe Acrobat Pro. Confirm that the form fields are named Date1, Date2, and Date3 and that the input dates use the mm/dd/yyyy format.
Add a custom calculation script to Date3 in Adobe Acrobat
Use this method to calculate Date3 automatically when both input dates are present.
The script compares the two dates, adds 1,096 calendar days to the later one, and formats the result as mm/dd/yyyy. It leaves Date3 blank if an input is missing or cannot be parsed.
Open the PDF in Adobe Acrobat Pro and select All tools > Prepare a form. Create or confirm the text fields Date1, Date2, and Date3.
Double-click Date3 to open its properties. On the Calculate tab, select Custom calculation script and click Edit.
In the JavaScript editor, enter the following script and confirm the dialog: var s1 = this.getField("Date1").valueAsString; var s2 = this.getField("Date2").valueAsString; try { var d1 = s1 ? util.scand("mm/dd/yyyy", s1) : null; var d2 = s2 ? util.scand("mm/dd/yyyy", s2) : null; if (!d1 || !d2 || isNaN(d1.getTime()) || isNaN(d2.getTime())) { event.value = ""; } else { var later = d1 > d2 ? d1 : d2; later.setDate(later.getDate() + 1096); event.value = util.printd("mm/dd/yyyy", later); } } catch (e) { event.value = ""; }
Save the PDF, exit form editing, and enter dates in Date1 and Date2. Check that Date3 updates when either input changes and remains blank when either input is empty.

Calculate dates in WPS Spreadsheets
WPS Office is a free, lightweight alternative with a familiar interface and compatible Office formats for an easy transition. WPS Spreadsheets can calculate the same date in a worksheet, although this does not add an Acrobat JavaScript calculation to a PDF form.

Frequently Asked Questions
What happens if one date field is empty?
The script leaves Date3 blank until both Date1 and Date2 contain dates that can be parsed.
Where do I put the calculation script in Acrobat?
Select All tools > Prepare a form, double-click Date3, and open Calculate > Custom calculation script > Edit.
Why does the calculation work in Acrobat but not in my browser?
Some browser PDF viewers do not support Acrobat form JavaScript. Open the saved form in a viewer that supports it and test the fields again.
Can I calculate the same result in a spreadsheet?
Yes. If A1 and B1 contain valid spreadsheet dates, enter =MAX(A1,B1)+1096 in another cell and format that cell as a date. This calculates a worksheet result, not a PDF form field.




