How to calculate time difference in Excel: hours worked, night shifts and totals over 24 hours
The difference between two times in Excel: hours worked, hourly pay, MOD for night shifts, the [h]:mm format for totals over 24 hours, and the ##### error.
A timekeeper records when each employee arrives and leaves. At month end the question is: how many hours did each person work, and what is their hourly pay? A café’s night shift starts at 22:00 and ends at 06:00; a call center’s weekly total is far beyond 24 hours.
The key rule: in Excel, time is a fraction of a day. 12:00 = 0.5; 18:00 = 0.75; 1 hour = 1/24. So you can simply subtract two times: =C2-B2. The trouble spots are three: converting the result to hours, crossing midnight, and totals larger than 24 hours.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Employee | In | Out | Worked | Hours | |
| 2 | Aziz Karimov | 09:00 | 18:00 | 09:00 | 9,00 | |
| 3 | Dilnoza Rakhimova | 08:30 | 17:45 | 09:15 | 9,25 | |
| 4 | Malika Yusupova | 10:15 | 19:00 | 08:45 | 8,75 | |
| 5 | Javokhir Turaev | 22:00 | 06:00 | 08:00 | 8,00 | |
| 6 |
Method 1: simple subtraction and the hh:mm format
1
Enter times with a colon: 9:00, 17:45. Excel aligns them to the right — that means they were recognized as times.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Employee | In | Out | Worked | |
| 2 | Aziz Karimov | 09:00 | 18:00 | ||
| 3 | Dilnoza Rakhimova | 08:30 | 17:45 | ||
| 4 | |||||
| 5 |
2
Type =C2-B2 in D2. Excel applies a time format to the result automatically: 9:00. Fill down — Dilnoza gets 9:15.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Employee | In | Out | Worked | |
| 2 | Aziz Karimov | 09:00 | 18:00 | 09:00 | |
| 3 | Dilnoza Rakhimova | 08:30 | 17:45 | 09:152 | |
| 4 | |||||
| 5 |
3
Need to subtract lunch? =C2-B2-ВРЕМЯ(1;0;0) takes off a one-hour break.
Method 2: decimal hours — ×24 for payroll
1
Hourly pay needs 9.25, not 9:15. Since time is a fraction of a day, multiply by 24: =(C2-B2)*24. For minutes, multiply by 1440 (=(C2-B2)*1440).
2
If you see 06:00 instead of 9.25, Excel gave the formula a time format. Select the cell and on Главная in the Number group choose General or Number.
3
Now the pay: =D2*$G$1, where G1 is the hourly rate (say 25,000 soums). 9.25 × 25,000 = 231,250 soums.
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | Employee | In | Out | Hours | Pay | 25 000 | ||
| 2 | Aziz Karimov | 09:00 | 18:00 | 9,00 | 225 000 | |||
| 3 | Dilnoza Rakhimova | 08:30 | 17:45 | 9,25 | 231 250 | |||
| 4 | ||||||||
| 5 |
Method 3: night shifts — with MOD
1
Javokhir arrives at 22:00 and leaves at 06:00. =C5-B5 = 0.25 − 0.9167 is negative, and Excel can’t display negative time — the cell shows #######.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Employee | In | Out | Worked | |
| 2 | Javokhir Turaev | 22:00 | 06:00 | ####### | |
| 3 | |||||
| 4 | |||||
| 5 |
2
The fix: =ОСТАТ(C5-B5;1). MOD adds a day to a negative difference: −0.6667 → 0.3333 = 8:00. For day shifts MOD changes nothing, so you can use it for the whole column.
3
An alternative: =C5-B5+(C5<B5). When Out is smaller than In, (C5<B5) is TRUE = 1, and one day is added.
Totals over 24 hours: the [h]:mm format
Add up a week’s hours with =СУММ(D2:D6) and instead of 42:30 you get 18:30. It isn’t a bug: hh:mm shows the “time of day” and drops each full 24 hours (1 day).
The fix is to put the hours in square brackets: select the cell → Ctrl + 1 → Number tab → Custom → type [h]:mm in the Type box. The brackets mean “don’t roll hours over at 24”. Likewise [m] is total minutes and [s] total seconds.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Day | Worked | Total (hh:mm) | Total ([h]:mm) | ||
| 2 | Monday | 08:30 | 18:30 | 42:30 | ||
| 3 | Tuesday | 09:15 | ||||
| 4 | Wednesday | 08:45 | ||||
| 5 | Thursday | 08:00 | ||||
| 6 | Friday | 08:00 | ||||
| 7 |
Pro level: dates with times, overtime and rounding to 15 minutes
- Spans of several days: if the cells hold date and time together (25.10.2025 22:00 → 27.10.2025 06:00), plain subtraction works:
=(C2-B2)*24→ 32 hours. Don’t use MOD here — it would swallow the days. - Overtime: anything over 8 hours —
=МАКС(0;D2-ВРЕМЯ(8;0;0)), or in decimal hours=МАКС(0;E2-8). - Round to 15 minutes: a day has 96 quarter-hours, so
=ОКРУГЛ(D2*96;0)/96. In Excel=MROUND(D2;"0:15")works too. - Show it in text:
=ТЕКСТ(D7;"[h]:mm")&" hrs"→ “42:30 hrs”. - Classify shifts: arrivals after 18:00 are night shifts:
=ЕСЛИ(B2>=ВРЕМЯ(18;0;0);"Night";"Day").
Try it in the simulator
B and C hold times as fractions of a day (0.375 = 9:00). Type =(C2-B2)*24 in D2 and fill down to D5 — Javokhir’s night shift gives a negative number. Then type =ОСТАТ(C2-B2;1)*24 in E2, fill down and compare.
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Employee | In | Out | Hours | With MOD | |||||||||||||||||||
| 2 | Aziz Karimov | 0,375 | 0,75 | |||||||||||||||||||||
| 3 | Dilnoza Rakhimova | 0,354166666667 | 0,739583333333 | |||||||||||||||||||||
| 4 | Malika Yusupova | 0,427083333333 | 0,791666666667 | |||||||||||||||||||||
| 5 | Javokhir Turaev | 0,916666666667 | 0,25 | |||||||||||||||||||||
| 6 | ||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||
| 10 |
Has ExcelLab been useful?
Support the project and help us release new lessons and exercises.