Hello, I'm hoping someone can assist me with this issue as I have been working for 5 days on this. I am trying to calculate the total time for 1 day between 2 times and subtract 30 minutes for the break. Then I need the sum of the time for the week. for Example: Johnny worked 2 days, on day 1 he clocked in at 07:45 and clocked out at 16:30. Then on day 2 he clocked in at 08:00 and clocked out at 16:45. I need to get the total time he worked on day 1 and day 2 subtracting 30 minutes. Then I need the total time he worked for the 2 days together.
I found the following function that works fine to give me the total time but it doesn't subtract the 30 minutes. I've tried several modifications to the code but can't seem to get the correct results. Any help would be much appreciated. Here's the function:
I basically call this function in the control on a form. Example: =HoursAndMinutes([TimeOut]-[TimeIn])
Then for the sum of the that: =HoursAndMinutes(Sum([TimeOut]-[TimeIn]))
If only I can get the code to subtract the 30 minutes for lunch, I'd be oh so grateful.
Thanks
I found the following function that works fine to give me the total time but it doesn't subtract the 30 minutes. I've tried several modifications to the code but can't seem to get the correct results. Any help would be much appreciated. Here's the function:
Code:
Public Function HoursAndMinutes(interval As Variant) As String
'***********************************************************************
' Function HoursAndMinutes(interval As Variant) As String
' Returns time interval formatted as a hours:minutes string
'***********************************************************************
Dim totalminutes As Long, totalseconds As Long
Dim hours As Long, minutes As Long, seconds As Long
If IsNull(interval) = True Then Exit Function
hours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440)) ' 1440 = 24 hrs * 60 mins
minutes = totalminutes Mod 60
totalseconds = Int(CSng(interval * 86400)) ' 86400 = 1440 * 60 secs
seconds = totalseconds Mod 60
If seconds > 30 Then minutes = minutes + 1 ' round up the minutes and
If minutes > 59 Then hours = hours + 1: minutes = 0 ' adjust hours
HoursAndMinutes = hours & ":" & Format(minutes, "00")
End Function
I basically call this function in the control on a form. Example: =HoursAndMinutes([TimeOut]-[TimeIn])
Then for the sum of the that: =HoursAndMinutes(Sum([TimeOut]-[TimeIn]))
If only I can get the code to subtract the 30 minutes for lunch, I'd be oh so grateful.
Thanks