How to Calculate Timesheet Hours Across Midnight in Acrobat Forms
Question details
The user needs to calculate total hours worked based on time-in and time-out fields within a PDF timesheet, specifically requiring a solution for shifts that cross midnight.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Designing a functional and automated PDF timesheet form for employee time tracking.
- Observed behavior
- Standard subtraction calculations result in negative or incorrect hours when a work shift begins on one day and ends on the next.
Verify that you have access to the 'Prepare Form' tool in Adobe Acrobat Pro, and note down the exact field names you plan to use for the start and end times to ensure your script references them correctly.
Use Custom JavaScript for Form Calculation
Implement a custom calculation script in the total hours field that parses the time inputs, calculates the difference, and automatically adds 24 hours if the shift crosses midnight.
Unlike spreadsheet software, PDF forms do not have built-in time calculation formulas. You will need to use Acrobat's JavaScript engine to split the time values, convert them into comparable numbers, and adjust for overnight shifts.
Launch Adobe Acrobat, open your PDF timesheet, and select the 'Prepare Form' tool from the right-hand panel.
Add text fields for your start and end times. Name them exactly 'TimeIn' and 'TimeOut', and ensure they are formatted to accept time values in the field properties.
Create a third text field named 'TotalHours'. Right-click on this field, select 'Properties', and navigate to the 'Calculate' tab.
Select 'Custom calculation script' and click the 'Edit' button. Write a JavaScript code that retrieves the values of 'TimeIn' and 'TimeOut', and splits the hours and minutes using the colon (:) as a separator.
In your script, subtract the start time from the end time. Add a condition stating that if the end time is numerically less than the start time, add 24 hours to the calculation, then assign the final result to 'event.value'.

Create and Calculate Timesheets Easily with WPS Spreadsheet
While PDF forms require complex JavaScript for time calculations, WPS Spreadsheet simplifies this process using built-in formulas. You can easily calculate hours worked across midnight and export the final document as a clean PDF.
- 1. Set Up Your Columns: Open WPS Spreadsheet and create columns labeled 'Time In', 'Time Out', and 'Total Hours'.
- 2. Enter Shift Times: Input your work hours into the respective columns using standard time formats (e.g., 10:00 PM, 06:00 AM).
- 3. Apply the Formula: In the 'Total Hours' column, enter the formula =MOD(EndTimeCell - StartTimeCell, 1) * 24. This formula automatically corrects negative values for overnight shifts.
- 4. Format and Export: Format the Total Hours cell as a standard number. Once your timesheet is ready, go to Menu > Export to PDF to share it.

Frequently Asked Questions
Why does my Acrobat time calculation show a negative number?
If a shift starts before midnight and ends after midnight (e.g., 10:00 PM to 6:00 AM), the numeric value of the end time is smaller than the start time. You must include logic in your JavaScript to add 24 hours to the end time when this occurs.
Can I use standard Excel formulas directly in PDF forms?
No, Adobe Acrobat PDF forms do not support standard spreadsheet functions like MOD or SUMIF. You must use Simplified Field Notation for basic arithmetic or JavaScript for complex scenarios like time parsing.
How do I hide the total hours result when the form is blank?
In your custom JavaScript, add a conditional statement (if/else) at the very beginning to check if the 'TimeIn' or 'TimeOut' fields are empty. If they are missing data, set the event.value to an empty string ("").
What time format should users input into the PDF form?
It is highly recommended to standardize the input format. Set the text field properties in Acrobat to strictly accept either 24-hour time (HH:MM) or 12-hour time with AM/PM so your JavaScript can reliably parse the text strings.




