Datediff to calculate hours worked Weirding out

lmac

Board Regular
Joined
May 12, 2005
Messages
103
Hi, I'm using

Total Hours Worked: DateDiff("n",[Start Time],[End Time])/60

to calculate employee hours worked for the day. It works fine except for employees who work after 12midnight. I'm using 24hr format for Start & End time. This is what I get for someone who worked 3:00pm-4:00am.

Start Time 15:00
End Time 04:00
Total Hours Worked = -11.00 ???? (Why am I getting negative # when it should be 13.00 total hours)

Any help?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi
This is happening because you are only looking at the times, not the dates and quite rightly, the end time is less than the start time. (I know this isn't really the case but this is what Access thinks).

There are 2 ways to get around this. The first is to correct the problem which would be to use fields in your datediff function that incorporate the date and time (e.g. StartDateTime and StartDateEnd - both would be General Date format).

The other (quick and dirty) way would be to make an adjustment in your formula, like this :

DateDiff("n",[Start Time],[End Time])/60+IIf([End Time]<[Start Time],24,0)

HTH, Andrew :)
 
Upvote 0
Txs andrew, I used the quik & dirty way in order to keep my 24 hr format data entry field. It worked perfectly! Txs again.
 
Upvote 0

Forum statistics

Threads
1,203,125
Messages
6,053,656
Members
444,676
Latest member
locapoca

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top