PDF Editing Issues

How to Calculate Daily Hours Worked in an Acrobat PDF Timesheet

Bushra ParveenBushra Parveen Nov 10, 2026 868 views

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.

How to Calculate Daily Hours Worked in 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.
Before you start

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.

Solution 1Recommended

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.

1
Open Field Properties

In your PDF form editor, right-click the text field where you want the total hours to appear and select 'Properties'.

2
Select Custom Calculation

Navigate to the 'Calculate' tab inside the Properties dialog and select the 'Custom calculation script' option.

3
Add the Conversion Function

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; }

4
Calculate the Total

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));

5
Format as Decimal Hours

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.

Use Custom Acrobat JavaScript to Calculate Decimal Hours
Time Input Format: For this script to function properly, ensure the times entered in the Clock In and Clock Out fields follow the 'h:MM tt' format (e.g., 8:00 AM or 5:30 PM).
Manage PDFs with WPS

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. 1. Download WPS Office: Download and install WPS Office on your computer or mobile device.
  2. 2. Open Your Timesheet: Open your timesheet document in WPS PDF or WPS Spreadsheet.
  3. 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. 4. Export as PDF: Export or save your completed timesheet directly as a high-quality PDF to share with HR or your manager.
Free to download and useFully compatible with Microsoft Excel and Adobe PDF formatsLightweight application with a familiar, user-friendly interfaceEasily calculate timesheets using built-in spreadsheet formulas instead of complex PDF JavaScript
microsoft office alternative - wps office

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.