Calculate PDF Timesheet Hours and Overtime in Adobe Acrobat
Question details
Calculate hours in a PDF timesheet without showing NaN for blank time fields, and separate hours above 40 as overtime.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A fillable PDF timesheet needs daily hours, a regular-hours total capped at 40, and an overtime total.
- Observed behavior
- Blank time entries can produce NaN, and the weekly total needs to be divided into regular and overtime hours.
Open the PDF in Acrobat and use Prepare a form to check the exact names of the In, Out, daily hours, regular hours, and overtime fields. The example below assumes seven shifts, 24-hour time entries such as 09:30, and no unpaid breaks.
Add Acrobat JavaScript calculations to the PDF timesheet
Use custom field calculations to leave incomplete shifts blank and split weekly hours at 40.
The example uses In1 through In7, Out1 through Out7, and Hours1 through Hours7. Replace these names with the actual field names in your PDF. It supports shifts crossing midnight but not shifts of 24 hours or longer.
In Acrobat, open All tools > Prepare a form. Open the properties of Hours1, select Calculate, choose Custom calculation script, and click Edit.
Enter this script for Hours1. It leaves the result blank if either entry is blank or does not match HH:MM, and otherwise calculates decimal hours: var a = this.getField("In1").valueAsString.replace(/^\s+|\s+$/g, ""); var b = this.getField("Out1").valueAsString.replace(/^\s+|\s+$/g, ""); var pattern = /^([01]?\d|2[0-3]):([0-5]\d)$/; var start = pattern.exec(a); var end = pattern.exec(b); if (!start || !end) { event.value = ""; } else { var minutesIn = Number(start[1]) * 60 + Number(start[2]); var minutesOut = Number(end[1]) * 60 + Number(end[2]); event.value = ((minutesOut - minutesIn + 1440) % 1440) / 60; }
Open Calculate > Custom calculation script for each remaining Hours field. Copy the script and change In1 and Out1 to the matching field names, such as In2 and Out2.
Open the regular-hours field properties and choose Calculate > Custom calculation script > Edit. Enter: var total = 0; for (var i = 1; i <= 7; i++) { total += Number(this.getField("Hours" + i).valueAsString) || 0; } event.value = Math.min(total, 40);
Open the overtime field properties and choose Calculate > Custom calculation script > Edit. Enter: var total = 0; for (var i = 1; i <= 7; i++) { total += Number(this.getField("Hours" + i).valueAsString) || 0; } event.value = Math.max(total - 40, 0);
In Prepare a form, use More > Set field calculation order to place all daily Hours fields before the regular and overtime fields. Preview the form, leave some time fields blank, then enter enough shifts to test a total above 40 hours.

Calculate timesheet hours in WPS Spreadsheet
Build the timesheet in WPS Spreadsheet using formulas for daily, regular, and overtime hours, then export the completed sheet as a PDF. The exported PDF is a report, not an Acrobat JavaScript form.
- 1. Create time columns: Open WPS Spreadsheet and create columns for In, Out, and Hours. Enter shift times in cells A2:B8 and format the time columns as Time.
- 2. Calculate daily hours: In C2, enter =IF(OR(A2="",B2=""),0,MOD(B2-A2,1)*24), then fill the formula down through C8. Format column C as Number.
- 3. Split regular and overtime hours: Enter =MIN(SUM(C2:C8),40) in a regular-hours cell and =MAX(SUM(C2:C8)-40,0) in an overtime cell. These formulas assume no unpaid breaks and shifts shorter than 24 hours.
- 4. Save or export the timesheet: Use File > Save As to keep an editable spreadsheet, or use File > Export to PDF to create a PDF report.

Frequently Asked Questions
Why does my PDF timesheet show NaN?
A calculation may try to convert a blank or invalid time entry into a number. In Prepare a form, edit the daily hours field's custom calculation script to check both time fields before calculating.
How are hours above 40 separated as overtime?
Add the daily hours, then use Math.min(total, 40) for regular hours and Math.max(total - 40, 0) for overtime in the respective Acrobat field calculation scripts.
Can the calculation handle a shift that crosses midnight?
Yes. The example adds 1,440 minutes before applying the remainder operation, so a shift such as 22:00 to 06:00 calculates as 8 hours. It does not support shifts of 24 hours or longer.
Why are the totals not updating correctly?
In Acrobat's Prepare a form tool, check More > Set field calculation order and place the daily hours fields before the regular and overtime fields. Also verify that the script's field names match the form.
Will a PDF exported from WPS Spreadsheet retain the spreadsheet formulas?
The exported PDF shows the calculated results as a report; it does not retain the spreadsheet formulas as editable Acrobat form calculations. Keep the spreadsheet to update the timesheet later.




