Display Negative Date Differences in Adobe Acrobat Forms
Question details
Calculate the number of days between two dates in an Adobe Acrobat form and handle reversed or missing dates.

- Product
- Adobe Acrobat forms
- Device & OS
- not provided
- Scenario
- A form calculates a day difference from start and end date fields.
- Observed behavior
- The calculation uses Math.abs, which converts negative differences into positive numbers.
Identify the exact names and date formats of the start and end fields. You need access to the form's custom calculation script in Adobe Acrobat.
Remove Math.abs from the Acrobat form calculation
Use the signed date difference to show negative results, and leave the result blank when a date is missing or cannot be parsed.
Math.abs turns a negative number into a positive one. The example below retains the original inclusive calculation, which adds one day to the result.
In Acrobat, open the PDF and choose Prepare a form. Open the properties of the field that displays the day count, then select Calculate and edit its custom calculation script.
Replace the calculation with the following, changing StartDate, EndDate, and mm/dd/yyyy to match your form: var start = this.getField("StartDate").valueAsString; var end = this.getField("EndDate").valueAsString; event.value = ""; if (start && end) { try { var d1 = util.scand("mm/dd/yyyy", start); var d2 = util.scand("mm/dd/yyyy", end); if (d1 && d2) { event.value = Math.round((d2 - d1) / 864e5) + 1; } } catch (e) { event.value = ""; } }
Close the field properties and preview the form. Enter dates in both orders, then clear one date to check that the result becomes blank.

Display N/A for a reversed date range
Use this option when a reversed range should be marked as invalid instead of showing a signed number.
Calculate Date Differences in WPS Spreadsheets
For date calculations outside an Acrobat form, use the free, lightweight WPS Office suite. Its familiar spreadsheet interface and Excel format support make it easy to move existing worksheets. WPS does not modify Acrobat form scripts.

Frequently Asked Questions
Why does my Acrobat form always show a positive day count?
The calculation may use Math.abs, which converts negative results to positive numbers. Open the result field's Calculate settings and remove Math.abs if you need a signed difference.
How do I leave the result blank when a date is missing?
In the custom calculation script, set event.value to an empty string first and calculate only when both date fields have values that can be parsed.
Why does a reversed range of one day display zero?
The inclusive formula adds 1 to the signed difference. Remove + 1 from the result field's calculation if you want a one-day reversed range to display -1.
Can the form display N/A for an end date before the start date?
Yes. In the custom calculation script, compare the parsed dates and assign "N/A" when the end date is earlier. Make sure the result field's format permits text.




