Sheets Formula to Calculate Hours Worked: Step-by-Step
In this article
To calculate hours worked in Google Sheets, subtract the start time from the end time and multiply the result by 24. For example, if your start time is in cell A2 and your end time is in cell B2, the formula is =(B2-A2)*24. This converts the internal time value (which Sheets treats as a fraction of a day) into a decimal number representing total hours.
This guide covers how to set up your spreadsheet, handle shifts that cross over midnight, and format your cells so the math remains accurate. Whether you are managing a small team or tracking your own freelance hours, these steps ensure you don't run into common "time math" errors.
What You'll Need
- A Google account with access to Google Sheets.
- A basic table containing at least two columns: one for the start time and one for the end time.
- Consistent time entry (e.g., always using AM/PM or 24-hour format).
Step-by-Step
- Set Up Your Columns: Create a header row. Label column A as "Date," column B as "Start Time," column C as "End Time," and column D as "Total Hours."
- Enter Your Data: Input your times. For example, enter
8:00 AMin B2 and5:00 PMin C2. Ensure you include the space before AM or PM so Google Sheets recognizes the entry as a "Time" format rather than plain text. - Apply the Basic Formula: Click on cell D2 and type the following formula:
=(C2-B2)*24. Press Enter.- Why multiply by 24? Google Sheets stores time as a fraction of a 24-hour day. For example, 12 hours is stored as 0.5. Multiplying by 24 converts that fraction into the actual number of hours.
- Format the Result as a Number: By default, Sheets might try to format the result in cell D2 as a time (showing something like 9:00 AM). To fix this:
- Select cell D2.
- Go to the top menu and select Format > Number > Number.
- The cell should now display
9.00.
- Handle Unpaid Breaks: If you need to subtract a lunch break, add a "Break" column (Column E) where you enter the break duration in hours (e.g., 0.5 for 30 minutes). Update your formula in D2 to:
=(C2-B2)*24-E2. - Drag the Formula Down: Click the small blue square in the bottom-right corner of cell D2 and drag it down to apply the calculation to all your rows.
- Calculate the Grand Total: At the bottom of your "Total Hours" column, use the SUM function. If your data ends at row 10, type
=SUM(D2:D10)to get the total hours for the period.
Common Mistakes
- Forgetting the Parentheses: If you write
=C2-B2*24, Sheets follows the order of operations and multiplies B2 by 24 first, resulting in a massive negative number. Always wrap the subtraction in parentheses:(C2-B2). - Mixing Time Formats: Entering some times as
14:00and others as2:00 PMin the same column can sometimes confuse the formatting. Stick to one consistent method. - Using Text Instead of Time: Typing "8am" (without the space) may cause Sheets to treat the entry as text. If the cell is aligned to the left, it is likely text; if it is aligned to the right, it is recognized as a number/time.
Tips
- Use Data Validation: To prevent typos, select your time columns and go to Data > Data validation. Add a rule for "Is valid time" to ensure only proper time formats are entered.
- Quick Time Entry: Use the keyboard shortcut
Ctrl + Shift + ;(Windows) orCmd + Shift + ;(Mac) to insert the current time instantly into a cell. - Conditional Formatting: Use Format > Conditional formatting to highlight cells where total hours exceed 8 per day, helping you spot overtime quickly.
Troubleshooting
If your formula is not working as expected, try these steps in order:
- Check the Cell Format: If you see a strange time (like 12:00 AM) instead of a number, go to Format > Number > Number. This is the most common issue.
- Check for Negative Results: If you get a negative number or a series of hashtags (#######), it is likely because the end time is technically "smaller" than the start time (which happens during overnight shifts). See the "Overnight Shifts" section in the FAQ.
- Verify Data Type: Double-click the time cells. If they are entered as
'8:00 AM(with a leading apostrophe), Sheets treats them as text. Remove the apostrophe. - Refresh the Sheet: If the formula seems stuck, refresh the browser page to ensure all calculations are updating.
Frequently Asked Questions
How do I calculate hours for a shift that crosses midnight?
Standard subtraction fails if a shift starts at 10:00 PM and ends at 6:00 AM. Use the MOD function to handle this: =MOD(C2-B2, 1)*24. The MOD(..., 1) part tells Sheets to reset the clock at midnight, ensuring the result is always positive.
How do I convert minutes into decimals (e.g., 8 hours 30 mins to 8.5)?
The *(B2-A2)*24 formula does this automatically. Because it converts the time fraction to a base-10 number, 30 minutes will naturally appear as .5, and 15 minutes as .25.
Can I calculate total pay based on these hours?
Yes. Once you have the decimal hours in Column D, create a "Pay" column. If the hourly rate is $20, use the formula =D2*20. Ensure the Pay column is formatted as Format > Number > Currency.
What if I want the result to look like "8h 30m" instead of "8.5"?
If you prefer the time format, remove the *24 from your formula. Use =C2-B2 and then go to Format > Number > Custom date and time. Choose the duration format (Hours:Minutes). Note that you cannot easily multiply this format by a dollar amount for payroll.
How do I handle varying break times for different days?
Create a dedicated "Break" column. Enter the break as a time (e.g., 0:30 for 30 minutes). Your formula would then be =(C2-B2-E2)*24. This subtracts the break duration from the total shift duration before converting it to a decimal.