Okay. I assume the data is already in a "Time format" and that you want the result in "decimal" format to be used for other calculations: from the result = 08:00:00 to the result = 8.00 hours. Date/Time calculations automatically does a conversion to the type "double" and the result is given in a ratio that can be converted from seconds to minutes or hours.
For good measure you need a date field (e.g.; 1/20/2012) to make sure you can calculate a time difference if someone checks in late at night on one day and checks out early the next morning (e.g.; 11:00 PM to 1:00 AM). The date and the times have to be in the same value. Then you would have: checkin "1/20/2012 06:00:00 PM" and checkout "1/22/2012 02:00:00 AM." The time calculations will see the date crossover because of its conversion to the "double type."
The calculation follows this order:
-
1)Subtract the Date/Times: Result is a Date/Time type.
-
-
2) Convert to Double type (0.00000000)
-
-
3) Multiply the result * 86400 (to get seconds) and divide by 60 (to get minutes) and divide by 60 again (to get hours).
-
-
4) "Round" to the precision desired (2 or maybe 3) to get for example, 8.25 hours.
-
There are built in time functions for various programming languages that you could use but I have to know what it is if you want to work the calculations outside of the SQL server.
Here are 2 Update queries that should work in SQL server. One only uses a conversion to double, the other uses a function called DateDiff to make the conversion and shorten the math.
The inside calculation is:
CDbl([Hours]![checkout]-[Hours]![checkIn])*86400/60/60,
then I Round it so the final looks like this (note the precision 2 on the end):
Round(CDbl([Hours]![checkout]-[Hours]![checkIn])*86400/60/60,2)
-
UPDATE Hours SET Timeclock.TotHours = Round(CDbl([Hours]![checkout] - [Hours]![checkin]) * 86400/60/60, 2)
-
WHERE (((Hours.EmpID)="100"));
-
You might also be able to use: Round(DateDiff("n",[Hours]![checkIn],[Hours]![PunchOut]) /60,2), where the "DateDiff" function take away the seconds and minutes calculations.
-
UPDATE Hours SET Timeclock.TotHours = Round(DateDiff("n",[Hours]![checkIn],[Hours]![checkOut])/60,2)
-
WHERE (((Hours.EmpID)="100"));
-
Are there any complications I'm unaware of?