Calculate Days Between PDF Date Fields in Adobe Acrobat
Question details
Calculate the days between two PDF form date fields and leave the result blank until both dates are entered.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A form collects check-in and check-out dates and displays their calculated day count in a separate field.
- Observed behavior
- The existing calculation displays 1 when both date fields are blank.
Open the PDF in Adobe Acrobat with form-editing tools available, and confirm the exact names and date format of the check-in and check-out fields. The script below expects dates in dd/mm/yyyy format.
Add a conditional calculation script to the result field
Use a custom calculation script to leave the result blank when either date is missing and calculate the difference when both are available.
In Adobe Acrobat, open the PDF and select All tools > Prepare a form.
Open the properties of each date field and confirm its name and date format. This example uses “Check In Date 3” and “Check Out Date 3” with the format dd/mm/yyyy.
Open the result field’s Properties, select the Calculate tab, choose Custom calculation script, and click Edit. Enter: var checkIn = this.getField("Check In Date 3").valueAsString; var checkOut = this.getField("Check Out Date 3").valueAsString; event.value = ""; if (checkIn && checkOut) { try { var d1 = util.scand("dd/mm/yyyy", checkIn); var d2 = util.scand("dd/mm/yyyy", checkOut); if (d1 && d2 && !isNaN(d1.valueOf()) && !isNaN(d2.valueOf())) { event.value = Math.round((d2.valueOf() - d1.valueOf()) / 86400000); } } catch (e) { event.value = ""; } }
Close the field properties, preview the form, and enter both dates. Clear either date to confirm the result becomes blank, then select File > Save.

Work with PDF forms and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Microsoft Office files. Its format support makes it easy to bring existing documents into your workflow. Use Adobe Acrobat or another compatible PDF viewer to create and test the custom JavaScript calculation described above.

Frequently Asked Questions
Why does the original PDF calculation show 1 when the date fields are blank?
The original script adds 1 without first checking whether both fields contain dates. Check the field values before parsing them and set event.value to an empty string when either is missing.
How do I count both the check-in and check-out dates?
In the result field’s custom calculation script, add + 1 after the Math.round(...) expression. For example, May 1 through May 3 will then display 3 instead of 2.
What if my PDF uses a different date format?
In Prepare a form, check each date field’s Properties > Format. Change the pattern passed to util.scand in the calculation script to match the entered format, such as mm/dd/yyyy.
Will the calculation work in every PDF viewer?
Not necessarily. The result depends on the viewer’s support for PDF form JavaScript and whether JavaScript is enabled. Test the saved form in the viewer recipients will use.




