PDF Editing Issues

Calculate Days Between PDF Date Fields in Adobe Acrobat

Rana GarciaRana Garcia Nov 18, 2026 868 views

Question details

Calculate the days between two PDF form date fields and leave the result blank until both dates are entered.

Calculate Days Between PDF Date Fields in Adobe Acrobat
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the form editor

In Adobe Acrobat, open the PDF and select All tools > Prepare a form.

2
Check the date fields

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.

3
Add the calculation

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

4
Test and save the form

Close the field properties, preview the form, and enter both dates. Clear either date to confirm the result becomes blank, then select File > Save.

Add a conditional calculation script to the result field
Inclusive day counts: The script calculates elapsed days, such as 2 days from 01/05/2026 to 03/05/2026. To count both the check-in and check-out dates, add + 1 after the Math.round(...) expression. Replace the field names and date pattern if your form uses different ones.
Free Microsoft Office alternative

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.

Open and review PDF forms alongside other documentsWork with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXNavigate documents with a familiar, easy-to-use interfaceMove existing Office files into a lightweight, free workspace
microsoft office alternative - wps office

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.