PDF Editing Issues

Calculate Decimal Hours from AM/PM Times in an Acrobat Form

Nimra MalikNimra Malik Nov 19, 2026 869 views

Question details

Calculate elapsed time between AM/PM form fields as decimal hours rounded to the nearest quarter hour.

Calculate Decimal Hours from AM/PM Times in an Acrobat Form
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form collects start and end times, such as 12:00 PM and 1:30 PM, and needs a calculated decimal-hours result.
Observed behavior
The form should display 1.50 for the example and handle an end time that falls after midnight.
Before you start

Open the PDF in Acrobat with access to Prepare a Form and custom calculation scripts. Decide which fields will hold the start time, end time, and calculated result.

Solution 1Recommended

Add a custom calculation script to the Acrobat form

Use this method to calculate quarter-hour decimal values from two AM/PM text fields, including intervals that cross midnight.

1
Create the time fields

Open the PDF in Acrobat and choose All tools > Prepare a form. Add two text fields named StartTime and EndTime, and leave them as plain text so users can enter times such as 12:00 PM.

2
Create the result field

In Prepare a form, add a text field named DecimalHours. Open its Properties, select the Calculate tab, and choose Custom calculation script > Edit.

3
Enter the calculation

Paste this JavaScript into the editor and confirm it: function timeMinutes(value) { var text = String(value).replace(/^\s+|\s+$/g, ""); var match = /^(\d{1,2}):(\d{2})\s*(AM|PM)$/i.exec(text); if (!match) return null; var hour = Number(match[1]); var minute = Number(match[2]); if (hour < 1 || hour > 12 || minute > 59) return null; hour = hour % 12; if (match[3].toUpperCase() === "PM") hour += 12; return hour * 60 + minute; } var start = timeMinutes(this.getField("StartTime").value); var end = timeMinutes(this.getField("EndTime").value); if (start === null || end === null) { event.value = ""; } else { var elapsed = end - start; if (elapsed < 0) elapsed += 24 * 60; event.value = (Math.round((elapsed / 60) * 4) / 4).toFixed(2); }

4
Test and save the form

Select Preview in Prepare a form, enter 12:00 PM in StartTime and 1:30 PM in EndTime, and confirm that DecimalHours displays 1.50. Test an overnight interval, then save the PDF.

Add a custom calculation script to the Acrobat form
Overnight assumption: If the end time is earlier than the start time, the script treats it as the next day. Equal times return 0.00, so this method cannot distinguish zero hours from a full 24-hour interval.
Free Microsoft Office alternative

Work with PDFs and time calculations in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for viewing PDFs and working with time calculations in spreadsheets. Its Microsoft Office format compatibility makes it easy to bring existing files across. It does not replace the Acrobat form script above.

View PDF documents alongside your other office filesUse spreadsheets to organize time entries and decimal-hour calculationsOpen and work with Microsoft Excel XLSX and other Office formatsNavigate documents with a familiar, easy-to-use interface
QA img-9

Frequently Asked Questions

How does the calculation round to the nearest quarter hour?

The script divides elapsed minutes by 60, then uses Math.round(hours * 4) / 4. It displays the result with two decimal places, such as 1.50.

Can the form calculate a shift that ends after midnight?

Yes. When EndTime is earlier than StartTime, the script adds 24 hours to the difference. For example, 11:00 PM to 1:00 AM returns 2.00.

Why is the calculated field blank?

Check that the fields are named StartTime and EndTime and that both values use a time such as 9:30 AM. The script leaves DecimalHours blank when either entry is missing or invalid.

What happens if the start and end times are the same?

The script returns 0.00. To represent a full-day interval or durations longer than 24 hours, add date fields and use a calculation that includes the dates.