Google Sheets – Calculate Work Hours

formulasgoogle sheetsgoogle-sheets-dates

Given work hours for each weekday (let's say 9:00:00-17:00:00 Monday through Friday), a start timestamp (e.g., 1/15/2019 6:15:15) and end timestamp (e.g., 1/21/2019 14:35:10)…

How can I get the total work hours between start and end, excluding all other hours (i.e., weekends, 17:00:01-8:59:59)?

I'm in need of a basic, reusable formula that does the following for many cases:

  • Start: 1/15/2019 6:15:15
  • End: 1/21/2019 14:35:10
  • Work Hours: 37:35:10

Note again here that I don't want all hours for each day counted, only those within the work hours for each day.

NETWORKDAYS sadly does not give the exact decimal needed.

Best Answer

=NETWORKDAYS(TO_DATE(A2), TO_DATE(B2)) * (E2-D2) -
 IF(INDEX(SPLIT(A2, " "), 1, 2) > D2, D2 - INDEX(SPLIT(A2, " "), 1, 2), ) -
 IF(INDEX(SPLIT(B2, " "), 1, 2) < E2, E2 - INDEX(SPLIT(B2, " "), 1, 2), )

  • column A and column B formatted as Date time
  • column D and column E formatted as Time
  • column C formatted as Duration