PDF Editing Issues

How to Calculate a Dollar Amount from Start and End Dates in Acrobat

Amos GikundaAmos Gikunda Nov 10, 2026 869 views

Question details

The user wants to calculate the number of days between a start date and an end date in an interactive PDF form and multiply that difference by a specific dollar amount to display a total.

Calculate a Dollar Amount from Start and End Dates in Acrobat
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating an interactive PDF form that automatically calculates billing costs or fees based on a specified date range.
Observed behavior
The form requires a custom JavaScript calculation script in the result field to correctly parse date strings, compute the elapsed days, and apply a numerical multiplier.
Before you start

Ensure your PDF form already has properly formatted text fields created for 'Start Date', 'End Date', and the final calculation result field before applying the script.

Solution 1Recommended

Use a Custom JavaScript Calculation in Acrobat

Apply a custom script in the result field's calculation properties to parse the date values, calculate the difference in milliseconds, convert it to days, and multiply by your dollar rate.

Acrobat JavaScript allows you to retrieve values from date fields using valueAsString. By converting these strings into date objects with util.scand(), you can find the difference in total days and multiply it by a fixed rate or a variable rate from another field.

1
Open Field Properties

Open your PDF form in Acrobat's Prepare Form mode. Right-click the field where you want the final dollar amount to appear and select 'Properties'.

2
Enable Custom Calculation

Navigate to the 'Calculate' tab in the Properties window. Select the 'Custom calculation script' option and click the 'Edit' button.

3
Input the JavaScript Code

Enter the script to read the dates. Start with: var startDateString = this.getField('Start Date').valueAsString; var endDateString = this.getField('End Date').valueAsString; Ensure the field names exactly match the ones in your document.

4
Add Blank Field Handling

Prevent calculation errors when the form is empty by adding: if (startDateString == '' || endDateString == '') event.value = '';

5
Calculate Date Difference and Rate

Complete the script by converting the dates and doing the math: else { var d1 = util.scand('m/d/yy', startDateString); var d2 = util.scand('m/d/yy', endDateString); var diffInDays = Math.round((d2.getTime() - d1.getTime()) / 86400000); event.value = diffInDays * 200; } Replace 200 with your actual dollar amount.

Use a Custom JavaScript Calculation in Acrobat
Including the First Day: Standard date subtraction calculates elapsed time. If your billing requires including the starting day (so that same-day is 1 day), modify the calculation to: event.value = (diffInDays + 1) * 200;

Easily Calculate Date-Based Costs with WPS Office

Instead of writing complex JavaScript code for PDF forms, use WPS Spreadsheet to instantly calculate date differences and dollar amounts, then seamlessly export your customized invoice or form directly to a polished PDF document.

  1. 1. Open WPS Spreadsheet: Launch WPS Office and create a new Spreadsheet to act as your billing form or invoice.
  2. 2. Enter Your Dates: Input your Start Date in cell A1 and your End Date in cell B1.
  3. 3. Calculate the Days: In cell C1, simply type the formula =B1-A1 (or =B1-A1+1 to include both boundary dates) to automatically find the total number of days.
  4. 4. Apply the Dollar Amount: In cell D1, multiply the total days by your rate by entering =C1*200. Format the cell as Currency.
  5. 5. Export to PDF: Go to the Menu and click 'Export to PDF' to generate a clean, unalterable document to send to your clients.
Seamlessly calculates date differences without requiring any programming knowledge.Highly compatible with Microsoft Excel formulas (like DATEDIF) for accurate calculations.Easily export your finished calculation sheets to high-quality PDF files.Free and lightweight alternative to heavy and expensive PDF editors.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the calculation result exclude the first day?

Subtracting one date from another calculates the strictly elapsed time between them. To include both the start and end dates in your billing calculation, you must add 1 to the difference in days before multiplying by your dollar amount.

How do I reference another field for the dollar amount rate instead of a fixed number?

Replace the fixed number in your script with a variable that retrieves the value from your rate field. For example, add 'var rate = Number(this.getField("Rate Field Name").value);' and then change the final line to 'event.value = diffInDays * rate;'.

What happens if the date fields are left blank on the PDF?

If the fields are blank, the script may throw an error or return an incorrect value (like zero or NaN). Always use an 'if' statement to check if either date string is empty before running the conversion and calculation.