Calculate Elapsed Hours and Minutes

Since time answers are usually represented with Text variables (using the 99:99 A.M. text format) in HotDocs, there is no simple way to perform calculations with time variables. For example, to calculate the elapsed hours and minutes between two times, each time must first be split into its individual components (hours, minutes, and A.M./P.M.) before the times can be compared.

Example

In this example, the start and end times are first translated into a number of minutes since midnight. This means that a start time of 10:15 A.M. is 615 minutes (10 hours = 600 minutes + 15 minutes). Likewise, an end time of 12:30 P.M. is translated to 750 minutes. Once these two values are calculated, the elapsed time is simply the difference between the two numbers, which in this case is 135 minutes. This answer is then reduced to hours and minutes to calculate the final answer.

In this computation, Start Time is the starting time (using the 99:99 A.M. text format).

End Time is the ending time (using the 99:99 A.M. text format).

Start Minutes is a temporary Number variable used to save the start time as a total number of minutes.

End Minutes is a temporary Number variable used to save the end time as a total number of minutes.

Total Hours is a temporary Number variable used to save the total number of hours elapsed.

Total Minutes is a temporary Number variable used to save the total number of minutes elapsed.

Note: This computation assumes both times are on the same day. If not, you must modify the computation to consider the start and end date:

```""

//Calculate the starting time in minutes.
SET Start Minutes TO INTEGER( FIRST( Start Time, 2 ) )
IF Start Time CONTAINS "a"  // A.M.
IF Start Minutes = 12
SET Start Minutes TO 0
ELSE
SET Start Minutes TO Start Minutes * 60
END IF
ELSE  // P.M.
IF Start Minutes = 12
SET Start Minutes TO Start Minutes * 60
ELSE
SET Start Minutes TO Start Minutes * 60 + ( 12 * 60 )
END IF
END IF
SET Start Minutes TO Start Minutes + INTEGER( MID( Start Time, 4, 2 ) )

//Calculate the ending time in minutes.
SET End Minutes TO INTEGER( FIRST( End Time, 2 ) )
IF End Time CONTAINS "a"  // A.M.
IF End Minutes = 12
SET End Minutes TO 0
ELSE
SET End Minutes TO End Minutes * 60
END IF
ELSE  // P.M.
IF End Minutes = 12
SET End Minutes TO End Minutes * 60
ELSE
SET End Minutes TO End Minutes * 60 + ( 12 * 60 )
END IF
END IF
SET End Minutes TO End Minutes + INTEGER( MID( End Time, 4, 2 ) )

//Calculate the total time in hours and minutes.
SET Total Minutes TO REMAINDER( End Minutes - Start Minutes, 60 )
SET Total Hours TO TRUNCATE( ( End Minutes - Start Minutes ) / 60, 0 )

//Format the result of the computation.
"Elapsed Time: «Total Hours» hours and «Total Minutes» minutes."```