Menu

How to Calculate Time in Excel: Hours Between Two Times

=B2-A2 returns the time between a start time in A2 and an end time in B2: format it as h:mm to see 8:30, or multiply by 24 for 8.5 hours. Shifts over midnight, totals over 24 hours and pay from hours worked.

Every sheet on this page is live: change a number or a formula and it recalculates.

=B2-A2 returns the time between a start time in A2 and an end time in B2. Excel stores a time as a fraction of a day (12:00 is 0.5), so the result is a fraction too: format it as h:mm to read 8:30, or multiply by 24 to get 8.5 hours.

Hours worked
C2
ABCD
1StartEndHoursDecimal hours
29:0017:308:308.50
38:1516:458:308.50
47:3012:004:304.50
513:0018:205:205.33
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

The first row is 8:30 as a time and 8.50 as a number. 13:00 to 18:20 is 5:20, or 5.33 hours. Use the h:mm column when people read the result and the decimal column when it feeds a calculation such as pay. In a cell formatted as General, the same result shows as the raw fraction, 0.354167 for 8:30.

Add or subtract hours and minutes

Adding a time to a time works the same way. TIME(hours, minutes, seconds) builds the amount to add, or divide by 24 for hours and by 1440 for minutes.

Add and subtract time
B2
ABCD
1StartPlus 1:30Plus 45 minutesMinus 2 hours
29:0010:309:457:00
314:2015:5015:0512:20
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

From 9:00 the three columns give 10:30, 9:45 and 7:00; from 14:20 they give 15:50, 15:05 and 12:20. A time can also be typed in quotes: =A2+"1:30" adds an hour and a half.

Calculate time over midnight

A night shift from 22:00 to 6:00 ends "before" it starts, so =B2-A2 is negative: -16 hours. A time cannot be negative, and Excel fills the cell with #####. MOD(B2-A2,1) adds one day to a negative result and leaves a positive one alone, so it works for day and night shifts in the same column.

Shifts that cross midnight
C2
ABCD
1StartEndHoursDecimal hours
222:006:008:008.00
39:0017:008:008.00
423:307:157:457.75
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

The three shifts are 8:00, 8:00 and 7:45 long. Another way to write it is =B2-A2+(B2<A2): the comparison is 1 when the end time is earlier, which adds a day. When start and end are full date-times (2026-03-14 22:00), plain subtraction is enough, because the dates already say which day each time is on.

Sum hours over 24 hours

h:mm shows a time of day, so it wraps around at 24: a week of 42 hours 30 minutes is shown as 18:30. The format [h]:mm, with square brackets, shows total hours without wrapping.

Weekly total: h:mm and [h]:mm
C7
ABCD
1StartEndHoursTotal as [h]:mm
28:0016:308:30
38:0016:308:30
49:0017:308:30
58:0016:308:30
68:0016:308:30
7Total18:3042:30
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

C7 shows 18:30 and D7 shows 42:30. Both cells hold the same number (1.77 days); only the format differs. To set it: Home > Number Format > More Number Formats > Custom, and type [h]:mm. For the total as a decimal, multiply by 24: 42.5.

Convert time to decimal hours and back

Multiply a time by 24 for hours, by 1440 for minutes. To go back, divide decimal hours by 24 and format the cell as h:mm. HOUR and MINUTE return the parts of a time as whole numbers.

Time and decimal hours
B2
ABCDEF
1TimeHoursMinutesHOURMINUTEBack from hours
26:456.754056456:45
31:201.33801201:20
40:500.83500500:50
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

6:45 is 6.75 hours, 405 minutes, hour 6 and minute 45. 1:20 is 1.33 hours. HOUR returns 0 to 23 only, so for a duration of more than a day use =INT(A2*24) instead. Column F turns the decimal hours back into the original times. If =A2*24 shows 18:00 in your workbook, the result took the time format of A2: set the cell to General or Number.

Practice: pay and night shifts

Your turn: pay for the day
D2
ABCD
1StartEndRatePay
28:3016:0018
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In D2, calculate the pay: the hours between the start in A2 and the end in B2, times the hourly rate in C2.

Your turn: hours over midnight
C2
ABC
1StartEndHours
222:005:30
39:0017:00
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In C2, return the length of the shift as decimal hours, then fill it down to C3. A shift may run past midnight.

Why a time result shows ##### or a decimal

Three display problems account for most time questions:

  • #####: the result is a negative time, usually an overnight shift calculated with =B2-A2. Use =MOD(B2-A2,1). (A column that is too narrow shows ##### too; widen it to tell the two apart.)
  • A decimal like 0.354: the cell is formatted as General. Apply h:mm, or multiply by 24 if you wanted hours.
  • A total that is too small: the sum passed 24 hours and h:mm wrapped. Use [h]:mm.

Times typed as text ('9:00, or values pasted from another system) are not numbers: SUM skips them, so a total of such cells comes out too small or 0. =ISNUMBER(A2) returns TRUE for a real time; =TIMEVALUE(A2) converts text such as "9:00".

Frequently Asked Questions

How do I calculate the hours between two times in Excel?

Subtract the start from the end, =B2-A2, and format the cell as h:mm. For the hours as a number, multiply by 24: =(B2-A2)*24 turns 8:30 into 8.5.

How do I calculate time over midnight in Excel?

Use =MOD(B2-A2,1). A shift from 22:00 to 6:00 gives -16 hours with plain subtraction; MOD adds a day to any negative result, which gives 8:00.

Why does my total of hours reset after 24 hours?

The h:mm format shows the time of day, so 42 hours 30 minutes is shown as 18:30. Format the total as [h]:mm (Home > Number Format > More Number Formats > Custom) to show 42:30.

How do I convert time to decimal hours in Excel?

Multiply by 24: =A2*24. Excel stores a time as a fraction of a day, so 6:45 is 0.28125 and times 24 is 6.75 hours. Multiply by 1440 for minutes.

How do I add minutes to a time in Excel?

=A2+TIME(0,45,0) adds 45 minutes. =A2+45/1440 does the same, since a day has 1440 minutes. TIME also takes hours: TIME(2,30,0) is two and a half hours.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED