Hopefully this will make sense, I have a report with a start time / date, and a number of hours, and have a defined start / end time for a working day. However, my start and end times are causing a problem, and I can't seem to figure out a way around it. The work day starts at 6am, and ends at 2am. If I set the work day to end at 11:59pm, then my formula works fine, as soon as I cross over to 00:00am, then it gives me a #NUM! error.

This is the formula that I am using:

=WORKDAY(P6,CEILING((N6+MOD(P6,1)-U$1)/(U$2-U$1),1)-1)+MOD(P6,1)+(M6+N6)-CEILING(MOD(P6,1)+N6-U$1,U$2-U$1)+U$2-U$1

P6 contains the start time, N6 contains the number of hours, U1 contains the day start, and U2 contains the day end. I assume Excel is getting confused as it is seeing my end time (2am) as before my start time (6am). Can anyone help?

Thanks.