Home›Blog›Guides

How to Calculate Working Hours in Excel (With Formulas)

How to calculate working hours in Excel: copy-paste formulas for time in and out, breaks, night shifts, totals over 24 hours, decimal hours and overtime.

29 Nov 2026·7 min read

Here is how to calculate working hours in Excel: subtract the time in from the time out, for example =D2-C2, and format the result as h:mm. Multiply by 24 to get decimal hours for payroll, use =MOD(D2-C2,1) for night shifts that end after midnight, and format weekly totals as [h]:mm so they do not reset after 24 hours.

Below are the formulas for every common case, each with cell references and a worked example you can copy.

Set up the sheet first

Use one row per employee per day, with these columns:

Column A B C D E F G
Holds Date Employee Time in Time out Break (minutes) Hours (h:mm) Hours (decimal)
Row 2 example 01-Dec-2026 Ali 9:00 AM 5:30 PM 45 7:45 7.75

Type times with a colon, either with AM or PM (9:00 AM) or in 24-hour form (17:30). If a time sits on the left side of its cell, Excel has stored it as text, and some formulas will fail. The errors table below shows the fix.

One idea explains every formula in this guide: Excel stores time as a fraction of a day. 12:00 PM is 0.5, one hour is 1/24 and one minute is 1/1440. That is why you multiply by 24 to get hours, and divide minutes by 1440 to turn them into time.

How do you calculate hours between two times?

In F2, type =D2-C2 and format F2 as Time, or as a custom format of h:mm. With 9:00 AM in C2 and 5:30 PM in D2, the result is 8:30. Microsoft’s own guide to adding and subtracting time in Excel uses the same method.

How do you subtract a lunch break?

  • Break typed in minutes (45 in E2): =D2-C2-E2/1440. Result: 8:30 minus 45 minutes = 7:45.
  • Break typed as a time (0:45 in E2): =D2-C2-E2. Same result.
  • Actual break out and break in recorded (say in I2 and J2): =(I2-C2)+(D2-J2). With 9:00 in, 1:00 PM out for lunch, 1:45 PM back and 5:30 PM out, the result is 4:00 plus 3:45 = 7:45.

How to calculate working hours in Excel for night shifts

A shift from 10:00 PM to 6:30 AM gives a negative result with =D2-C2, and Excel shows #### because it cannot display negative time. Wrap the subtraction in MOD:

=MOD(D2-C2,1)-E2/1440

MOD adds a full day whenever the time out is earlier than the time in. With 10:00 PM in C2, 6:30 AM in D2 and a 30-minute break in E2, the result is 8:00. The formula gives the same answer as plain subtraction for day shifts, so you can use it in every row.

An alternative that some people find easier to read: =IF(D2<C2,D2+1,D2)-C2-E2/1440.

If your sheet stores the full date and time in each cell (for example 01-Dec-2026 10:00 PM and 02-Dec-2026 6:30 AM), plain subtraction already works. It also copes with shifts longer than 24 hours, which MOD cannot.

Let attendance mark itself.

Zealtrack takes the clock-in and clock-out from each computer, fills timesheets by itself and builds late and overtime reports with CSV export. Free for unlimited users, no credit card.

Start free or book a 30-minute demo

How do you total hours over 24?

Add up a week with =SUM(F2:F6). With five days of 7:45, 8:30, 8:00, 9:15 and 7:30, the real total is 41 hours, but a normal time format shows 17:00, because Excel rolls over every 24 hours.

Fix it with a custom format. Select the total, press Ctrl+1, choose Custom and type [h]:mm. The square brackets tell Excel to keep counting hours past 24, and the cell now shows 41:00.

How do you convert hours to decimal for payroll?

Payroll needs 7.75 hours, not 7:45. In G2, type =F2*24 and format G2 as Number with two decimals. To round the result, use =ROUND(F2*24,2).

Watch the classic mistake: 7 hours 45 minutes is 7.75 hours, not 7.45. Minutes are sixtieths of an hour, so 45 minutes is 0.75 of an hour.

To go straight from the raw times to decimal hours in one cell, night shifts included: =ROUND(MOD(D2-C2,1)*24-E2/60,2). To turn a decimal back into time, divide by 24 and format as h:mm: =G2/24.

Worked example: say an employee is paid 300 an hour in your currency (a made-up rate). Their five days in G2:G6 add up to 41.00 in G7 with =SUM(G2:G6), and =G7*300 gives 12,300 for the week.

Weekly totals and overtime

Daily overtime beyond an 8-hour day, in H2: =MAX(0,G2-8). A 9.5-hour day gives 1.5.

Weekly totals in a long log. When one sheet holds many weeks and many people, put the week’s start date in K2 and the employee’s name in L2, then in M2:

=SUMIFS(G:G,A:A,">="&K2,A:A,"<"&K2+7,B:B,L2)

This adds every decimal hour for that person from the start date up to, but not including, the same day a week later. Weekly overtime beyond a 48-hour week, in N2: =MAX(0,M2-48).

Use the normal hours from your own contract and labour law in place of 8 and 48. For how overtime is paid in Pakistan, province by province, see our overtime calculator.

Common errors and how to fix them

What you see Why Fix
#### in the hours cell Negative time: the shift ended after midnight, or the column is too narrow Use =MOD(D2-C2,1), or widen the column
A weekly total of 17:00 instead of 41:00 The total passed 24 hours Custom format [h]:mm
0.32 instead of 7:45 The cell is formatted as Number Format it as h:mm, or multiply by 24 for decimal hours
#VALUE! error A cell holds text instead of a time, often after pasting from another system Retype the time, or convert it with =TIMEVALUE(TRIM(C2))
7:45 entered in payroll as 7.45 Minutes read as decimals Use =F2*24, which gives 7.75
Hours 12 off AM or PM missing, so 6:00 was read as 6:00 AM Type PM, or use 24-hour times such as 18:00

Skip the formulas

If you would rather not build this yourself, our free Excel attendance sheet already has the formulas: hours worked with breaks and night shifts, late minutes against your start time, overtime and a monthly register. It is free with no sign-up.

If the real problem is typing the times in, let them fill themselves. Zealtrack records time in and time out from each Windows or macOS computer: the first activity of the day is the clock-in and the last is the clock-out. Overnight shifts are supported, with a “day starts at” setting so a night shift counts as one working day. Timesheets fill themselves, every edit is logged, and every report exports to CSV, so you can keep using your Excel formulas for payroll. It is free for unlimited users, so you can start free and compare a week against your sheet. See how the records look on our timesheets page.

Excel can calculate working hours reliably once the formulas are right. Ready to stop typing times? Try Zealtrack free or book a 30-minute demo.

Frequently asked questions

How do I calculate hours worked in Excel with a lunch break?

Subtract the time in and the break from the time out. With the break in minutes in E2, use =D2-C2-E2/1440 and format the cell as h:mm. If the break is typed as a time such as 0:45, use =D2-C2-E2.

What is the Excel formula for night shift hours?

Use =MOD(D2-C2,1) for hours and minutes, or =MOD(D2-C2,1)*24 for decimal hours. MOD adds a day when the time out is earlier than the time in, so a 10:00 PM to 6:00 AM shift gives 8 hours.

How do I convert hours and minutes to decimal in Excel?

Multiply the time by 24 and format the result as a number: =F2*24. So 7:45 becomes 7.75. Add ROUND(…,2) if payroll wants two decimals.

Why does Excel show #### when I subtract times?

Either the result is negative, usually because the shift ended after midnight, or the column is too narrow. Use the MOD formula for night shifts and widen the column for the rest.

How do I sum hours over 24 in Excel?

Use =SUM() as normal, then give the total a custom format of [h]:mm. Without the square brackets, Excel resets to zero every 24 hours.

Track time without watching people.

Free for unlimited users. No credit card.

Start free Book a demo
Chat with us on WhatsAppPick the office nearest to you.Saudi Arabia+966 53 961 0354Pakistan+92 344 2928117