G
Ginzell
I'm doing a Time In /Time out / Total for Employee's and I'm using the
function below, but I'm not getting the right totals back.
I'm getting:
Time In Time Out Hours:Minutes
7:00:00PM 9:00:00AM -10
---
Total Hours = -10
If I use regular hours - say, 9-5 it works, but when I get into graveyard
shifts it messes up. Any help greatly appreciated.
Option Compare Database
Option Explicit
Public Function HoursAndMinutes(interval As Variant) As String
Dim totalhours As Long, totalminutes As Long, totalseconds As Long
Dim hours As Long, Minutes As Long, seconds As Long
If IsNull(interval) = True Then Exit Function
totalhours = Int(CSng(interval * 24))
hours = totalhours Mod 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
function below, but I'm not getting the right totals back.
I'm getting:
Time In Time Out Hours:Minutes
7:00:00PM 9:00:00AM -10
---
Total Hours = -10
If I use regular hours - say, 9-5 it works, but when I get into graveyard
shifts it messes up. Any help greatly appreciated.
Option Compare Database
Option Explicit
Public Function HoursAndMinutes(interval As Variant) As String
Dim totalhours As Long, totalminutes As Long, totalseconds As Long
Dim hours As Long, Minutes As Long, seconds As Long
If IsNull(interval) = True Then Exit Function
totalhours = Int(CSng(interval * 24))
hours = totalhours Mod 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