Calculate Weekdays Between Two Dates in Acrobat JavaScript
Question details
Calculate the number of weekdays between two dates in a PDF form, excluding Saturdays and Sundays.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A PDF form uses JavaScript to calculate a date difference, and the result should count only weekdays.
- Observed behavior
- The current calculation includes weekend days.
Open the PDF in a version of Adobe Acrobat that can edit form fields. Check the names and date formats of the start and end fields; the example below uses StartDate, EndDate, and mm/dd/yyyy.
Count weekdays with a custom Acrobat form calculation
Use this script when the start and end dates should both be included if they fall on weekdays.
The script checks each date with getDay(), counting values 1 through 5 and skipping Saturday and Sunday. It handles partial weeks but does not exclude public holidays.
In Acrobat, open Tools or All tools > Prepare a form. Open each date field's Properties and confirm its name and date format. Set or adapt the field names to StartDate and EndDate and use mm/dd/yyyy for this example.
Select or add the text field that will display the weekday count. Open Properties > Calculate, choose Custom calculation script, and select Edit.
Replace the calculation script with the following code, changing the field names or date format if needed: var startText = this.getField("StartDate").valueAsString; var endText = this.getField("EndDate").valueAsString; var format = "mm/dd/yyyy"; var result = ""; try { var start = util.scand(format, startText); var end = util.scand(format, endText); if (start && end && util.printd(format, start) === startText && util.printd(format, end) === endText && start <= end) { start.setHours(12, 0, 0, 0); end.setHours(12, 0, 0, 0); var count = 0; for (var day = new Date(start.getTime()); day <= end; day.setDate(day.getDate() + 1)) { var weekday = day.getDay(); if (weekday >= 1 && weekday <= 5) count++; } result = count; } } catch (e) { result = ""; } event.value = result;
Close the script editor and field properties, save the PDF, and enter test dates in the two date fields. For example, 05/01/2026 through 05/04/2026 should return 2.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface and support for common Office formats, making it easy to move existing documents into your workflow. Acrobat form JavaScript must still be edited and tested in Acrobat.

Frequently Asked Questions
Does the script include the start and end dates?
Yes. It counts each endpoint if it falls on a Monday through Friday. A same-day weekday range returns 1; a same-day weekend range returns 0.
Does this calculation exclude holidays?
No. The getDay() check excludes only Saturdays and Sundays. Excluding holidays requires an additional list of holiday dates and a check against that list.
Why is the result field blank?
Check that both date fields contain valid dates in mm/dd/yyyy format and that the start date is not later than the end date. In Prepare a form, also verify that the script's field names match the actual field names.
Where do I put the JavaScript in Acrobat?
Open Prepare a form, select the result text field, and go to Properties > Calculate > Custom calculation script > Edit. Paste the script there, rather than in either date field.




