# Calculating overnight hours

##### New Member
Hi guys,

I created a time entry spreadsheet for my company for employees who are working temporarily. However, the formula I have doesn't seem to calculate overnight hours well. The total hours keep coming-up as a negative. Does anyone know how to modify it so that I can calculate overnight hours? I have included my formula down below.

- If anyone knows how to attach a spreadsheet, please let me know, as this will be a lot easier.

Layout:
Time In (C9), Lunch Out (D9), Lunch In (E9), Time Out (F9), Total Hours (G9)

Formula:
=IF(((D9-C9)+(F9-E9))*24>8,8,((D9-C9)+(F9-E9))*24)

Thank so much!

### Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

#### JoeMo

##### MrExcel MVP
Excel Workbook
CDEFG
8InLunch outLunch InOutTot Hrs
97:00 AM11:00 AM12:00 PM4:00 PM8.00
107:00 PM10:00 PM11:00 PM4:00 AM8.00
117:45 PM11:00 PM12:00 AM4:30 AM7.75
Sheet14

##### New Member
Thank you so much for your help!

Replies
7
Views
116
Replies
2
Views
59
Replies
4
Views
83
Replies
4
Views
81
Replies
5
Views
82