How to Calculate Daily Hours Worked in an Acrobat PDF Timesheet
Question details
The user needs to calculate the total daily hours worked for two separate work periods and display the result in decimal hours within an Acrobat PDF timesheet.

- Product
- Adobe Acrobat PDF
- Device & OS
- not provided
- Scenario
- Creating a dynamic, fillable PDF timesheet that automatically sums up time intervals based on clock-in and clock-out inputs.
- Observed behavior
- Requires a custom JavaScript solution to accurately parse time fields, subtract them to find the duration in minutes, and output the total converted to decimal hours.
Ensure your PDF timesheet form has correctly named text fields (such as 'ClockIn1', 'ClockOut1', 'ClockIn2', and 'ClockOut2') and that you are in form editing mode to access field properties.
Use Custom Acrobat JavaScript to Calculate Decimal Hours
Applying a custom calculation script to the total hours field is the most reliable way to accurately convert time inputs into decimal hours for multiple work periods.
Time formats cannot be subtracted directly using standard sum formulas in a PDF. You must first convert the hours and minutes into a single unit (like minutes), perform the subtraction, and then format the result back into hours.
In your PDF form editor, right-click the text field where you want the total hours to appear and select 'Properties'.
Navigate to the 'Calculate' tab inside the Properties dialog and select the 'Custom calculation script' option.
Click the 'Edit' button and define a function to convert time to minutes by typing: function timeToMinutes(t) { var d = util.scand('h:MM tt', t); return d ? d.getHours() * 60 + d.getMinutes() : 0; }
Below the function, add the variables to compute the difference for both work periods: var total = (timeToMinutes(this.getField('ClockOut1').value) - timeToMinutes(this.getField('ClockIn1').value)) + (timeToMinutes(this.getField('ClockOut2').value) - timeToMinutes(this.getField('ClockIn2').value));
Finally, add the line to convert the total minutes back to hours and format it to two decimal places: event.value = util.printf('%.2f', total / 60); Click 'OK' to save and close the script window.

Create and Manage Timesheets Easily with WPS Office
WPS Office offers a comprehensive suite including a powerful PDF editor and a versatile Spreadsheet program. Whether you need to fill complex PDF forms or prefer the ease of calculating time in Excel formats, WPS handles both scenarios efficiently.
- 1. Download WPS Office: Download and install WPS Office on your computer or mobile device.
- 2. Open Your Timesheet: Open your timesheet document in WPS PDF or WPS Spreadsheet.
- 3. Calculate Easily: If using WPS Spreadsheet, simply use standard time subtraction formulas like =(Out-In)*24 to instantly calculate decimal hours without writing code.
- 4. Export as PDF: Export or save your completed timesheet directly as a high-quality PDF to share with HR or your manager.

Frequently Asked Questions
Why is my PDF timesheet calculation returning an error or zero?
This usually happens if the field names referenced in your script do not exactly match the actual field names in your PDF form, or if the time format entered by the user cannot be parsed by the util.scand function. Ensure correct spelling and case sensitivity.
Can I calculate timesheets without using JavaScript in a PDF?
While standard PDF forms require JavaScript to perform time-based math, you can bypass this complexity by building your timesheet in a spreadsheet program like Excel or WPS Spreadsheet, which natively handles time subtraction using simple cell formulas.
How do I format the total hours as a decimal in my PDF script?
You can format the output as a decimal by taking the total duration in minutes, dividing by 60, and passing it through the util.printf('%.2f', total / 60) function to restrict the result to two decimal places.




