G
Gina Whipp
Hello All,
I am at an impass and sometimes just seeing other ideas helps me think it
out, so here it goes...
(TimeIn - TimeOut) - LunchBreak relatively easy calculation BUT
If you arrive late you are docked in 15 minute increments (so 7:16 am means
you lose 30 minutes). If you leave early you are docked in 15 minute
increments. There are no exceptions, you can't 'make-up' the time. (Glad I
don't work there!)
What have I tried, that doesn't work:
15*Int(+[aTimeDecimal])/15
Don't know if this works because I can't get it to handle midnight...
Function HoursWorked(TimeIn As Variant, TimeOut As Variant) As Variant
'Thanks Allen Browne (found in the Newsgroup)
'Purpose: Return the difference in hours,
' rounding each argument to 15 minutes,
' and subtracting 30 minutes for lunch.
Dim dtTimeIn As Date 'TimeIn as a date, rounded to 15 min.
Dim dtTimeOut As Date 'TimeOut as a date, rounded to 15 min.
Dim lngMinutes As Long
Const lngcLunchBreak As Long = 30
'Initialize to Null
HoursWorked = Null
'Check the arguments aren't error/invalid.
If Not IsError(TimeIn) Or IsError(TimeOut) Then
If IsDate(TimeIn) And IsDate(TimeOut) Then
'Time since midnight, rounded to 15 minutes.
lngMinutes = 15 * CInt(DateDiff("n", #12:00:00 AM#, TimeValue(TimeIn)) / 15)
dtTimeIn = DateAdd("n", lngMinutes, DateValue(TimeIn))
lngMinutes = 15 * CInt(DateDiff("n", #12:00:00 AM#, TimeValue(TimeOut)) /
15)
dtTimeOut = DateAdd("n", lngMinutes, DateValue(TimeOut))
'subtract the lunch break, and convert to hours.
HoursWorked = (DateDiff("n", dtTimeIn, dtTimeOut) - lngcLunchBreak) / 60
End If
End If
End Function
Thanks,
Gina Whipp
"I feel I have been denied critical, need to know, information!" - Tremors
II
I am at an impass and sometimes just seeing other ideas helps me think it
out, so here it goes...
(TimeIn - TimeOut) - LunchBreak relatively easy calculation BUT
If you arrive late you are docked in 15 minute increments (so 7:16 am means
you lose 30 minutes). If you leave early you are docked in 15 minute
increments. There are no exceptions, you can't 'make-up' the time. (Glad I
don't work there!)
What have I tried, that doesn't work:
15*Int(+[aTimeDecimal])/15
Don't know if this works because I can't get it to handle midnight...
Function HoursWorked(TimeIn As Variant, TimeOut As Variant) As Variant
'Thanks Allen Browne (found in the Newsgroup)
'Purpose: Return the difference in hours,
' rounding each argument to 15 minutes,
' and subtracting 30 minutes for lunch.
Dim dtTimeIn As Date 'TimeIn as a date, rounded to 15 min.
Dim dtTimeOut As Date 'TimeOut as a date, rounded to 15 min.
Dim lngMinutes As Long
Const lngcLunchBreak As Long = 30
'Initialize to Null
HoursWorked = Null
'Check the arguments aren't error/invalid.
If Not IsError(TimeIn) Or IsError(TimeOut) Then
If IsDate(TimeIn) And IsDate(TimeOut) Then
'Time since midnight, rounded to 15 minutes.
lngMinutes = 15 * CInt(DateDiff("n", #12:00:00 AM#, TimeValue(TimeIn)) / 15)
dtTimeIn = DateAdd("n", lngMinutes, DateValue(TimeIn))
lngMinutes = 15 * CInt(DateDiff("n", #12:00:00 AM#, TimeValue(TimeOut)) /
15)
dtTimeOut = DateAdd("n", lngMinutes, DateValue(TimeOut))
'subtract the lunch break, and convert to hours.
HoursWorked = (DateDiff("n", dtTimeIn, dtTimeOut) - lngcLunchBreak) / 60
End If
End If
End Function
Thanks,
Gina Whipp
"I feel I have been denied critical, need to know, information!" - Tremors
II