How to Calculate the Duration Between Two Dates in an Acrobat Form
Question details
The user needs to calculate the number of days between a start date and an end date automatically within a fillable PDF form.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form (such as a booking or leave request) that requires calculating the total length of a stay based on user-entered dates.
- Observed behavior
- The user wants the PDF form to automatically subtract the start date from the end date and display the duration result in a designated calculated field.
Ensure that both your start date and end date fields use the exact same date format (e.g., mm/dd/yyyy) in their properties to prevent JavaScript calculation errors.
Implement a Custom JavaScript Calculation Script in Acrobat
Use Adobe Acrobat's built-in custom calculation script feature to convert date strings into JavaScript Date objects and find the difference in days.
By default, PDF forms do not have a built-in simple formula for date calculations. You must use a short JavaScript snippet that extracts the values from your date fields, calculates the difference in milliseconds, and converts that value into days.
Open your PDF document in Adobe Acrobat, go to the 'Tools' menu, and select 'Prepare Form' to enable form editing.
Right-click the text field where you want the calculated duration to appear, and choose 'Properties' from the context menu.
Navigate to the 'Calculate' tab inside the Properties dialog box, select 'Custom calculation script', and click the 'Edit' button.
Input a JavaScript snippet that defines your start and end date variables (using 'this.getField'), parses them into Date objects (utilizing 'util.scand'), and subtracts the start date from the end date. Divide the result by 86400000 (the number of milliseconds in a day) to get the day count.
Click 'OK' to save the script, close the Properties window, and test your form by entering sample start and end dates to verify the calculation.

View and Fill PDF Forms Easily with WPS PDF
WPS Office includes a highly capable PDF editor that allows you to seamlessly view, fill, and manage interactive PDF forms. If you need a lightweight and free alternative to heavy PDF software, WPS PDF offers an intuitive interface for all your daily document needs.
- 1. Download WPS Office: Download and install WPS Office on your computer or mobile device.
- 2. Open Your PDF Form: Launch WPS PDF and open the interactive PDF form you need to fill out.
- 3. Fill in the Data: Click directly on the interactive form fields to input your dates and text seamlessly.
- 4. Save and Share: Once completed, save the filled PDF directly to your device or share it via email.

Frequently Asked Questions
Why is my Acrobat date calculation returning a NaN (Not a Number) error?
This usually occurs if the date format entered by the user does not match the format expected by the JavaScript 'util.scand' function, or if one of the date fields is currently empty. You should add a condition in your script to check if the fields are empty before performing the calculation.
Can I calculate the time duration in hours instead of days?
Yes, Acrobat JavaScript allows for precise time calculations. Instead of dividing the millisecond difference by 86,400,000 (days), you would divide it by 3,600,000 to extract the total duration in hours.
Is there a way to calculate date differences in a PDF without writing JavaScript code?
Natively, Adobe Acrobat requires JavaScript for advanced date calculations. However, you can use third-party paid plugins or pre-made custom action scripts developed by external creators to apply these calculations without writing the code manually.




