Calculate Daily Working Hours in Google Sheets

Using a start and end time (timestamp), you can easily calculate daily working hours in Google Sheets, with the formula effectively handling cases where the start and end dates differ or include repeated dates.

The output will include a date column and an hours column. Using these, you can further analyze the data—for example, separating weekend hours, calculating overtime if an employee exceeds a specific number of hours in a day, etc. These additional tips are not included here but can be derived since the formula provides a detailed summary of working hours.

=ArrayFormula(
   LET(start, A2:A, end, B2:B, 
      hrs, 
      IF(
         INT(start)<>INT(end), 
         HSTACK((INT(end)-start)*24,(end-INT(end))*24), 
         N(IFNA(HSTACK(((end-start)*24),)))
      ), 
      hrsDt, 
      VSTACK(
         HSTACK(INT(start), CHOOSECOLS(hrs, 1)), 
         HSTACK(INT(end), CHOOSECOLS(hrs, 2))
      ), 
      QUERY(hrsDt, "SELECT Col1, SUM(Col2) WHERE Col2>0 GROUP BY Col1 LABEL Col1 'Date', SUM(Col2) 'Hrs'", 0)
   )
)

When using this formula, replace A3:A with your start datetime reference and B3:B with your end datetime reference.

To display the dates properly, select the first column of the result, then navigate to Format > Number > Date in Google Sheets.

Example of Daily Working Hours Calculation

Sample Data in Columns A and B:

Work Start Date & TimeWork End Date & Time
2018-04-23 10:00:002018-04-23 20:00:00
2018-04-24 10:00:002018-04-24 17:00:00
2018-04-25 17:00:002018-04-26 5:00:00
2018-04-26 17:00:002018-04-27 5:00:00
2018-04-28 10:00:002018-04-28 20:00:00
2018-04-29 10:00:002018-04-29 14:00:00
  • Column A contains the work start date and time (datetime format).
  • Column B contains the work end date and time (datetime format).

It is essential to use the date and time format for accurate calculations, especially for jobs spanning multiple days (e.g., night shifts). For example, in the work start and end times provided above, some shifts begin on one day and end on the following day.

If you enter the formula in cell D1, it will output the total working hours grouped by dates:

Example of calculating daily working hours in Google Sheets

How the Formula Calculates Daily Working Hours

The formula is broken into components using the LET function. Here’s how each component works:

Syntax of LET:

LET(name1, value_expression1, [name2, …], [value_expression2, …], formula_expression)

Defined Names and Their Functions:

  • start: Refers to the start datetime range (A2:A).
  • end: Refers to the end datetime range (B2:B).
  • hrs: Calculates the working hours split across different dates:

Logic:

If INT(start) <> INT(end) (dates are different):

HSTACK( (INT(end)-start)*24, (end-INT(end) )*24) // calculates hours for the start and end dates separately

Else:

N(IFNA(HSTACK(((end-start)*24),))) // calculates total hours for the same date

The formula produces a two-column output, with Column 1 showing the hours worked on the start date and Column 2 showing the hours worked on the end date.

Extracting hours worked, including shifts spanning two days
  • hrsDt:
VSTACK( HSTACK(INT(start), CHOOSECOLS(hrs, 1)), HSTACK(INT(end), CHOOSECOLS(hrs, 2)))

Combines dates and hours into a two-column table using:

HSTACK(INT(start), CHOOSECOLS(hrs, 1)): Stacks the start date with the hours worked on that date.

HSTACK(INT(end), CHOOSECOLS(hrs, 2)): Stacks the end date with the hours worked on that date.

Finally, VSTACK merges these rows into one table.

Stacking hours worked spanning two days into one column alongside corresponding dates
  • Formula Expression:
QUERY(hrsDt, "SELECT Col1, SUM(Col2) WHERE Col2>0 GROUP BY Col1 LABEL Col1 'Date', SUM(Col2) 'Hrs'", 0)

The QUERY formula summarizes the working hours for each date by selecting rows where hours (Col2) > 0, grouping the data by the date column (Col1), and calculating the total daily working hours for each date.

Resources for Further Exploration

Here are additional tutorials to enhance your calculations in Google Sheets:

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Compare Two Tables for Differences in Excel

To compare two tables with similar data for differences, you can use the XLOOKUP...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

More like this

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

9 COMMENTS

  1. Was there ever any follow-up to Mac’s issue? We need a similar thing. We have snowplow drivers that work consecutively 1-3 days, and we need to extract out the office hours of 7 am-3 pm so we can calculate overtime earned over multiple days.

    Any help would be greatly appreciated.

    Katie

  2. Oh man, thanks Prashanth for getting back to me so quickly, I hope there is a way around this. I’ve been wracking my brain (of limited spreadsheet knowledge) for days on this now – really hope you can solve this one 🙂 Thanks Again.

  3. Hi Prashanth, great spreadsheet.

    It is almost exactly what I need.

    However, my company must calculate different rates for night shift hours after a specific time in the evening too, not just after 8 hours of working.

    For example, weekdays between:
    – 8am to 5pm is £10p/hr,
    – 5pm to 11pm is £15p/hr and
    – 11pm to 8am is £20p/hr.

    How would we integrate this calculation into this exact same sheet including the weekend O.T rates you have shown above (FYI weekend rates are also charged at a higher rate than shift O.T hours for example:
    – 8am to 5pm is £15p/hr
    – 5pm to 11pm is £20p/hr
    – 11pm to 8am is £25p/hr

    • Hi, Mac,

      Sorry to say, this Sheet won’t work in that case because of the separate rate for working from 11 pm to 8 am.

      I may try to work on this problem later and link you here.

      Best,

  4. Thanks a lot for the information.

    In my company we have some break time throughout the day. Is it possible to exclude non working hours as well?

    • Hi, Ordan Gilboa,

      I guess the break time would be standard like 1 hour four lunch, 30 minutes for an evening break something like that for every day. Then we can do that.

      My formula returns total working hours in column range E3:E. So you can minus the break time directly from it using the below formula in cell F3.

      =ArrayFormula(if(len(D3:D),E3:E-1.5,))

      Format the column F to numbers from the menu Format > Number > Number.

      This formula subtracts 1.5 hours (1 hour 30 minutes) as a standard from the total working hours in each day. You can change this value as per your requirement.

      In cell G2, H2 and I2 change the cell reference E3:E to F3:F.

      I didn’t test this. But it must work.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.