Intermediate

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.

Книга1 - Excel
—☐✕
D5fx=ОСТАТ(C5-B5;1)
ABCDEF
1EmployeeInOutWorkedHours
2Aziz Karimov09:0018:0009:009,00
3Dilnoza Rakhimova08:3017:4509:159,25
4Malika Yusupova10:1519:0008:458,75
5Javokhir Turaev22:0006:0008:008,00
6
Готово
D shows time (9:15), E shows decimal hours (9.25) for payroll. Javokhir’s night shift uses MOD

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.

Книга1 - Excel
—☐✕
C3fx0,7395833333333334
ABCDE
1EmployeeInOutWorked
2Aziz Karimov09:0018:00
3Dilnoza Rakhimova08:3017: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.

Книга1 - Excel
—☐✕
D3fx=C3-B3
ABCDE
1EmployeeInOutWorked
2Aziz Karimov09:0018:0009:00
3Dilnoza Rakhimova08:3017:4509: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.

Книга1 - Excel
—☐✕
E3fx=D3*$G$1
ABCDEFGH
1EmployeeInOutHoursPay25 000
2Aziz Karimov09:0018:009,00225 000
3Dilnoza Rakhimova08:3017:459,25231 250
4
5
Готово
G1 is the hourly rate. Hours worked × rate = daily pay

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 #######.

Книга1 - Excel
—☐✕
D2fx#######
ABCDE
1EmployeeInOutWorked
2Javokhir Turaev22:0006:00#######
3
4
5
Готово
=C2-B2 is negative, so Excel can’t show the result

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.

Книга1 - Excel
—☐✕
D2fx=СУММ(B2:B6)
ABCDEF
1DayWorkedTotal (hh:mm)Total ([h]:mm)
2Monday08:3018:3042:30
3Tuesday09:15
4Wednesday08:45
5Thursday08:00
6Friday08:00
7
Готово
The same SUM: 18:30 in hh:mm (wrong), 42:30 in [h]:mm (right)

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.

Книга1 - Excel
—☐✕
Буфер обмена
Шрифт
Выравнивание
Число
Стили
Ячейки
Редактирование
✕✓fx
ABCDEFGHIJKLMNOPQRSTUVWX
1EmployeeInOutHoursWith MOD
2Aziz Karimov0,3750,75
3Dilnoza Rakhimova0,3541666666670,739583333333
4Malika Yusupova0,4270833333330,791666666667
5Javokhir Turaev0,9166666666670,25
6
7
8
9
10
Лист1
Готово

Has ExcelLab been useful?

Support the project and help us release new lessons and exercises.

Support us
Previous

149 / 154