How to Calculate Days Between Separate Date Fields in Adobe Acrobat
Question details
The user needs to automatically calculate the number of days between a start date and an end date in an Acrobat PDF form where the month, day, and year are provided in separate input fields.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Setting up a PDF form that requires an automatic calculation of the duration between two dates, but the date components are split into separate text fields.
- Observed behavior
- Because the dates are not in a single unified date field, standard date calculation methods do not work directly. The separate components must be combined programmatically to perform the subtraction.
Ensure you have the exact field names for all your separate month, day, and year fields for both the start and end dates before writing your calculation script.
Use Custom JavaScript for Date Calculation
Use Adobe Acrobat's custom JavaScript calculation feature to combine the separate fields into valid date objects and calculate the difference.
Since the dates are split into multiple fields, you cannot use Acrobat's predefined formatting or simplified field notation. You must use JavaScript to extract the values, construct a valid date format, and subtract the dates. The result is returned in milliseconds, which must then be converted to days.
Open your PDF form in Adobe Acrobat and enter 'Prepare Form' mode. Right-click the text field where you want the final number of days to appear and select 'Properties'.
In the Properties window, navigate to the 'Calculate' tab. Select the option for 'Custom calculation script' and click the 'Edit' button.
In the JavaScript editor, write a script to retrieve the values from your individual date fields. Use the this.getField('FieldName').value method to get the month, day, and year for both your starting and ending dates.
Combine the retrieved strings into a format recognized by JavaScript's Date object (e.g., 'MM/DD/YYYY'). Create Date objects for both the start and end dates, subtract the start date from the end date, and divide the result by 86,400,000 to convert the difference from milliseconds to days.
Assign the final calculated number to 'event.value'. Click 'OK' to save the script, close the properties window, and test your form by entering sample dates.

Fill and Manage PDF Forms Easily with WPS Office
WPS Office offers a comprehensive PDF editor that lets you view, fill, and manage interactive PDF forms effortlessly. It fully supports form field interactions and embedded scripts, making it a reliable choice for complex PDF documents.
- 1. Open your PDF form: Launch WPS Office and open the PDF file containing your form fields.
- 2. Access interactive fields: Click on the highlighted form fields to enter your separate month, day, and year information.
- 3. Automatic calculation: WPS PDF will seamlessly process the embedded JavaScript calculation and display the correct number of days automatically.

Frequently Asked Questions
Do I have to physically merge the date fields on the PDF form?
No, you do not need to merge the actual input fields. Your custom JavaScript will temporarily merge the values behind the scenes to perform the mathematical calculation without altering the form's layout.
Why does my day calculation show 'NaN' or a negative number?
This usually occurs if the calculation runs before all fields are filled out. Ensure your calculation script includes a validation check to verify all month, day, and year fields contain valid numbers before attempting the calculation.
How do I convert a JavaScript date difference into actual days?
When you subtract two JavaScript Date objects, the result is given in milliseconds. To convert this value into days, you must divide the result by 86,400,000, which represents the total number of milliseconds in a 24-hour period.
Can I use Acrobat's built-in simplified field notation instead of JavaScript?
No, simplified field notation only supports basic arithmetic (addition, subtraction, multiplication, division). Because dates require complex logic to account for different month lengths and leap years, custom JavaScript is required.




