
newbie question: how to figure hours worked each day
Here is something i wrote for a similar app. I used Access to store the
data. The database was set up to only handle 3 in's and 3 outs for each
day, but that is easly expanded. Hope this helps.
Nathan Enright
Dim Db As Database
Dim Rs1 As Recordset
Dim Rs2 As Recordset
Dim totalHours As Long
Dim totalSec As Long
Dim totalMin As Long
Set Db = OpenDatabase(datapath)
Set Rs1 = Db.OpenRecordset("Select * from [CurrentPeriod]",
dbOpenSnapshot)
lblPayStart = Rs1!StartingDate
lblPayEnds = Rs1!EndingDate
SQLQ = "Select * From [TimeTable] Where [UserName] = '" & Rs1!CurrentUser
_
& "' And [Date] >= #" & Rs1!StartingDate & "# And [Date] <= #" _
& Rs1!EndingDate & "#;"
Set Rs2 = Db.OpenRecordset(SQLQ, dbOpenSnapshot)
Do While Rs2.EOF = False
If Not Rs2!In3 Then
totalSec = totalSec + DateDiff("s", Rs2!In1, Rs2!Out1) + DateDiff("s",
Rs2!In2, Rs2!Out2) + DateDiff("s", Rs2!In3, Rs2!Out3)
ElseIf Not Rs2!In2 Then
totalSec = totalSec + DateDiff("s", Rs2!In1, Rs2!Out1) + DateDiff("s",
Rs2!In2, Rs2!Out2)
ElseIf Not Rs2!In1 Then
totalSec = totalSec + DateDiff("s", Rs2!In1, Rs2!Out1)
End If
Rs2.MoveNext
Loop
totalHours = totalSec / 3600
totalMin = (totalSec Mod 3600) / 60
totalSec = (totalSec Mod 3600) Mod 60
lblTotHours = totalHours
lblTotMin = totalMin
lblTotSec = totalSec
Quote:
>Copy this code to a button's event procedure to execute it...
>'*********************************************************
>Dim dteTimeIn As Date, dteTimeOut As Date, sngEmployeeHours As Single
>' Assign two times for example purposes only. You'll need to substitute
>' another way of entering times that makes sense in your app.
>dteTimeIn = #7/29/98 8:00:00 PM#
>dteTimeOut = #7/30/98 8:16:00 AM#
>' Calculates the difference between time in and time out.
>' You might want to change output with the Format function
>sngEmployeeHours = DateDiff("n", dteTimeIn, dteTimeOut) / 60
>' Display result in a message box.
>MsgBox (sngEmployeeHours)
>'*********************************************************
>Best regards,
>John Perkins
>>I want to create a program that figures the hours worked each day if you
>input
>>the time in and the time out. Sometimes the employee will clock in at 8pm
>one
>>day and out 8 am the next day. I appreciate any ideas.