How to Calculate Flight Time Across Midnight in PDF Forms
Question details
The user needs to calculate the elapsed time between military-format departure and arrival times in a PDF form, accounting for flights that cross midnight, and output the result in decimal tenths.

- Product
- Adobe Acrobat PDF
- Device & OS
- not provided
- Scenario
- Creating or filling a PDF flight log form where time inputs are in military format (HH:MM) and durations often span to the next day, requiring decimal hour formatting.
- Observed behavior
- Standard calculations fail or return negative numbers when the arrival time is numerically smaller than the departure time, requiring a custom script to handle the overnight rollover.
Ensure your PDF editor supports custom JavaScript calculations for form fields, and verify whether any logged flight duration will ever exceed 24 hours, as this requires a different formula.
Use a Custom JavaScript Calculation in Form Properties
Apply a custom JavaScript code to the elapsed time field that converts military time to minutes, adjusts for midnight crossings by adding 24 hours, and rounds to decimal tenths.
Built-in PDF math functions cannot interpret military time or handle next-day rollovers. By using a custom JavaScript script, you can parse the HH:MM format into total minutes. If the arrival time is earlier than the departure time, the script automatically adds 1440 minutes (24 hours) to calculate the correct duration.
Open your PDF document in your editor's form preparation mode so that all interactive fields are selectable.
Right-click the text field designated for the total flight time and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab inside the Properties dialog box, select the 'Custom calculation script' option, and click the 'Edit' button.
Write a script to retrieve the Departure and Arrival field values, split the hours and minutes, and convert both into total minutes from midnight.
Add logic to check if Arrival minutes are less than Departure minutes; if so, add 1440 to the Arrival. Subtract Departure from Arrival, divide by 60, and use Math.round(value * 10) / 10 to output the final decimal value to event.value.

Manage and Fill Advanced PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to interact with, edit, and fill complex PDF forms. Whether you're tracking flight times, utilizing calculation fields, or managing professional documents, WPS PDF streamlines your workflow.
- 1. Download WPS Office: Install WPS Office for free and launch the WPS PDF application on your device.
- 2. Open Your PDF Log: Click 'Open' and select your existing PDF flight log or calculation form.
- 3. Fill the Form Fields: Navigate through the document to input your military departure and arrival times.
- 4. Save and Export: Once your data is entered and automatically calculated, click 'Save' or export the document as a flattened PDF for sharing.

Frequently Asked Questions
Why does my flight time calculation show a negative number?
If a flight crosses midnight, the numerical value of the arrival time (e.g., 01:15) is smaller than the departure time (e.g., 22:35). Subtracting them directly results in a negative number. You must use a script to add 24 hours to the arrival time to prevent this.
How do I round the calculated flight time to decimal tenths?
In your custom JavaScript calculation, after calculating the total hours, multiply the value by 10, pass it through the Math.round() function, and then divide by 10. This converts a time duration like 2 hours and 42 minutes into exactly 2.7 hours.
Can I calculate flight times without using JavaScript in a PDF?
No, standard built-in PDF form calculations only support basic arithmetic (addition, multiplication, etc.). Parsing military time strings (HH:MM) and intelligently adjusting for midnight crossings strictly requires custom JavaScript.
What happens if a flight is longer than 24 hours?
If a flight duration exceeds 24 hours, a time-only calculation script is insufficient because it cannot distinguish between one day passing or multiple days. You will need to add departure and arrival date fields to your form and parse them alongside the time.




