Calculating the difference between two times in Google Sheets is a fundamental skill for anyone managing schedules, tracking project hours, or analyzing temporal data. Unlike simple number subtraction, time values in spreadsheets operate on a 24-hour cycle, which can lead to confusing results if the methodology is not understood correctly. This guide provides a clear, step-by-step approach to subtracting times, ensuring you always get the accurate duration you need.
Understanding Time Serial Numbers
Before diving into the formulas, it is essential to grasp how Google Sheets internally stores time. The platform treats dates and times as serial numbers, where the integer portion represents the day and the decimal portion represents the time of day. For example, 0.5 corresponds to 12:00 PM, and 0.75 corresponds to 6:00 PM. This decimal system is the reason why subtracting two times directly often yields unexpected results like negative numbers or dates instead of hours.
Basic Subtraction for Same-Day Durations
The most straightforward method applies when the start and end times occur on the same day. In this scenario, you can simply subtract the earlier time from the later time using a standard formula. If your start time is in cell A2 and your end time is in cell B2, the formula is as simple as =B2-A2 . To ensure the result displays correctly, format the cell containing this formula as "Duration" to see the elapsed time in hours and minutes rather than a confusing decimal serial number.
Applying Number Formatting
Formatting is a critical step that many users overlook. Even with the correct formula, your cell might display "12:00 AM" if it is not formatted properly. To fix this, select the cell with the result, navigate to the "Format" menu, choose "Number," and then select "Duration." This format tells Google Sheets to interpret the decimal value as a length of time, accurately displaying hours and minutes regardless of whether the total duration exceeds 24 hours.
Handling Overnight and Cross-Day Durations
Problems arise when the time period spans midnight, such as a shift starting at 10:00 PM and ending at 6:00 AM. In this case, the end time is numerically smaller than the start time, which causes Google Sheets to return a negative value or an error. To solve this, you must explicitly tell the sheet to assume the end time occurred on the following day. The formula =IF(B2 checks if the end time is less than the start time; if it is, the script adds 1 (representing a full 24-hour day) before performing the subtraction, ensuring the calculation returns a positive duration.
Extracting Hours and Minutes as Numbers
While duration formatting is useful for visual display, you often need the raw numbers for further calculations, such as payroll or billing. The HOUR and MINUTE functions allow you to extract these specific components. To get the total hours as a decimal number, use the formula =HOUR(B2-A2) + MINUTE(B2-A2)/60 . This breaks down the time difference, converts the minutes into a fractional hour, and combines them to give you a single, usable figure representing the total time worked.