
Industry
How to calculate working hours between two timestamps in Excel and Google Sheets
Count working hours between two timestamps by clipping each day's window to the interval. Seven worked intervals, a spreadsheet formula, and the break, time zone and clock-change edges.
A request arrives at 15:00 on a Friday and is answered at 11:00 on the Monday. On the wall clock that is 68 hours. Inside a 09:00 to 17:00, Monday-to-Friday week it is four. A report, a target or an invoice that does not say which of those it means is not saying anything.
This article gives the method, seven intervals worked by hand, and a formula that reproduces them in Excel and Google Sheets.
What to take away
- Working hours between two moments are the sum, over every working day the interval touches, of the overlap between that day's window and the interval.
- Friday 5 March 2027 at 15:00 to Monday 8 March at 11:00 is 68 elapsed hours and 4 working hours on a 09:00 to 17:00 weekday window.
- Forty working hours are five days on an eight-hour window and 5.33 days on a 7.5-hour window. Hours and days do not convert at a fixed rate.
- Spreadsheets store a time as a fraction of a day, so a working-hours formula returns a fraction of a day and needs multiplying by 24.
- A spreadsheet subtracts timestamps as plain numbers. Across a clock change the result is an hour out, and the file and script time zones are separate settings.
The method
Clip each working day's window to the interval, add what is left, and ignore everything else.
- Convert both ends of the interval to the governing time zone.
- List every working day from the start date to the end date. Skip rest days and closures.
- For each listed day, take the later of the window's opening and the interval's start, and the earlier of the window's closing and the interval's end.
- If that clipped span is positive, add its length. If it is zero or negative, the day adds nothing.
- Sum the days.
An interval that begins before the window opens counts from the opening. One that ends after closing counts to the close. A weekend or closed day adds nothing, however long the interval sits inside it.
Seven intervals, worked by hand
The window is 09:00 to 17:00, Monday to Friday, with no closures and one time zone. The dates are March 2027, and the elapsed hours sit beside the working hours so the gap is visible.
| From | To | Working hours | Elapsed hours |
|---|---|---|---|
| Fri 5 Mar 15:00 | Mon 8 Mar 11:00 | 4 | 68 |
| Fri 5 Mar 18:30 | Mon 8 Mar 08:00 | 0 | 61.5 |
| Tue 2 Mar 10:15 | Thu 4 Mar 14:45 | 20.5 | 52.5 |
| Mon 1 Mar 09:00 | Fri 5 Mar 17:00 | 40 | 104 |
| Sat 6 Mar 10:00 | Sun 7 Mar 16:00 | 0 | 30 |
| Fri 5 Mar 16:30 | Fri 5 Mar 17:30 | 0.5 | 1 |
| Mon 1 Mar 09:00 | Mon 8 Mar 09:00 | 40 | 168 |
The second row is the one to remember. Sixty-one and a half hours pass and none count, because the interval starts after Friday's close and ends before Monday's opening. The last row shows a full week of working hours inside one week of elapsed time.
What to settle before you count
Five inputs decide the answer: the window, the working week, the closure list, the zone and the resolution. Change any one and the count changes.
The window and the working week come from the contract, the service terms or the employer. Monday to Friday is an assumption. Editorial suggestion: take the closure list from the body whose hours you are counting rather than from a general holiday list. Country calendars explains who publishes them. The zone is the one named in the agreement or used by the office. The resolution is whatever the report will be judged in, to the minute or to the second.
Editorial suggestion: write all five next to every figure. A result of 20.5 hours cannot be checked without them and both timestamps.
Hours to days
A target written in one unit and reported in the other drifts by the difference each time it is converted.
At 8 a day
- 8
- 1
- 24
- 3
- 40
- 5
- 100
- 12.5
At 7.5 a day
- 8
- 1.07
- 24
- 3.2
- 40
- 5.33
- 100
- 13.33
At 7 a day
- 8
- 1.14
- 24
- 3.43
- 40
- 5.71
- 100
- 14.29
"Three working days" and "24 working hours" are the same target only on an eight-hour window. Pick one unit for the document. Month totals of working days, which is where many hour budgets start, are in working days per month.
The same count in Excel and Google Sheets
A spreadsheet stores a date-time as one number. The whole part is the day and the fraction is the time. Microsoft's TIME function page states that times are decimal numbers, with noon stored as 0.5. One hour is 1/24 of a day, so 09:00 is 9/24 and 17:00 is 17/24.
Put the start in A2 and the end in B2, with the end not before the start. Name three cells or ranges: Open (the opening time), Close (the closing time) and Closures (a range of closure dates). The formula uses NETWORKDAYS (Excel, Google Sheets), which takes a start date, an end date and an optional holidays range. Google notes that it treats only Saturday and Sunday as the weekend. Other weekends need NETWORKDAYS.INTL.
=ROUND(24*(
IF(INT(B2)>INT(A2), NETWORKDAYS(INT(A2), INT(B2)-1, Closures), 0)*(Close-Open)
+ NETWORKDAYS(INT(B2), INT(B2), Closures)*(MEDIAN(MOD(B2,1), Open, Close)-Open)
- NETWORKDAYS(INT(A2), INT(A2), Closures)*(MEDIAN(MOD(A2,1), Open, Close)-Open)
), 6)
Read it as three terms:
- The first term counts the working days from the start's date up to the day before the end's date, and gives each a full window.
- The second adds the end day's share.
MOD(B2,1)is the time of day,MEDIANclips it into the window, andNETWORKDAYS(INT(B2),INT(B2),Closures)is 1 on a working day and 0 on a weekend or closure. Both vendors' pages define the arguments as dates, so the formula passesINTof the timestamp instead of relying on how each product treats a time of day. - The third removes the start day's share the same way.
MEDIAN of a value and two bounds returns the value if it lies between them and the nearer bound if it does not. That is the clipping step in one function. INT rounds down to an integer, which strips the time and leaves the date (Google's INT page, MEDIAN page).
The check below uses five of the intervals above plus three more, and each expected value is the hand count from the method. The formula was also evaluated outside a spreadsheet, with the same arithmetic on serial numbers, and matched every row. That is not a test in Excel or Google Sheets, so enter the rows in your own sheet and compare before relying on the formula.
Expected hours
- 4Fri 5 Mar 15:00 to Mon 8 Mar 11:00
- 0Fri 5 Mar 18:30 to Mon 8 Mar 08:00
- 20.5Tue 2 Mar 10:15 to Thu 4 Mar 14:45
- 0Sat 6 Mar 10:00 to Sun 7 Mar 16:00
- 0.5Fri 5 Mar 16:30 to Fri 5 Mar 17:30
- 1Sat 6 Mar 12:00 to Mon 8 Mar 10:00
- 8Fri 5 Mar 08:00 to Fri 5 Mar 18:00
- 4Fri 5 Mar 15:00 to Tue 9 Mar 11:00, with 8 Mar in
Closures
The last row is why the closure range matters. Without Monday 8 March in the list the same interval returns 12. The ROUND wrapper removes floating-point residue such as 4.00000000006; Google's MOD page notes the same approximation issue and suggests ROUND.
Breaks. A lunch hour that does not count is a second window. Run the same expression with the break's start and end in place of Open and Close, then subtract it from the result. With a 12:30 to 13:30 break, Thursday 4 March from 08:00 to 18:00 gives 7 hours, and Friday 5 March 12:15 to Tuesday 9 March 10:45 gives 12.5.
Overnight windows. Editorial suggestion: split a 22:00 to 06:00 shift into 22:00 to midnight and midnight to 06:00 and apply the method to each.
Totals that wrap, and the time zone settings
A total over 24 hours shows as the remainder when the cell has a time-of-day format, so 30 hours appears as 6:00. The stored value is right. Excel's number format codes list [h]:mm as the elapsed-time format. Google's number format reference documents [h+] for elapsed hours. Multiplying by 24 and showing a plain number avoids the question.
In Google Sheets the file has a time zone under File, Settings, General, described on Google's spreadsheet settings page. An Apps Script project has its own. Google's reference for Session says that spreadsheet time zones that differ from the script time zone are a frequent source of scripting bugs. The script zone is a ZoneId such as America/Denver in its manifest. Use a named IANA zone rather than an offset, because the database records the history of clock changes and an offset does not.
A time typed into a cell is a number of days with no zone attached. Google's date and number formats guide says Sheets date-time serial numbers do not store a time zone offset and are based on the spreadsheet's time zone. That suits a window definition and does not suit an event log. Google's NOW and TODAY help pages do not say which time zone they use, so compare their output with a known local time instead of assuming.
Days that are not 24 hours
In the United States a clock change happens at 2 a.m. on the second Sunday of March and the first Sunday of November, under 15 U.S.C. 260a. A state may by law exempt itself from the change if it lies entirely in one time zone, so the rule does not apply to every US location. In 2027 the change dates are Sunday 14 March and Sunday 7 November. Other countries set their own dates.
A sheet subtracts two timestamps as plain numbers. Across the change it returns the wall-clock difference, not the elapsed time. In America/Chicago, Saturday 13 March 2027 at 22:00 to Sunday 14 March at 08:00 is 10 hours on a sheet and 9 hours elapsed. For the same zone, Saturday 6 November at 22:00 to Sunday 7 November at 08:00 is 10 on a sheet and 11 elapsed.
A 09:00 to 17:00 window is untouched, because the change falls in the small hours. Friday 12 March 15:00 to Monday 15 March 11:00 is 4 working hours either way, but 67 elapsed hours against 68 from subtraction. Editorial suggestion: count a window that spans 02:00 with elapsed arithmetic in a service, as described in the working hours API.
For contract clocks that turn these counts into due moments, see SLA deadline calculators. The day-level decisions underneath are in adding business days.
Sources
- Google Docs Editors Help, NETWORKDAYS
- Google Docs Editors Help, MEDIAN
- Google Docs Editors Help, INT
- Google Docs Editors Help, MOD
- Google Docs Editors Help, NOW
- Google Docs Editors Help, TODAY
- Google Docs Editors Help, Set a spreadsheet's location and calculation settings
In this guide
- Designing a working hours API: duration, add, is_open and next_openA working hours endpoint answers four questions: duration, add, is_open and next_open. Edge rules, a request and response shape with segments, a holiday feed, and test vectors.







