On Nov 21, 6:53 am, Anthos <anth...@itexcellence.com.auwrote:
The function datediff is your friend in this scenario.
An example is
datediff("H", #09:00#, #17:30#) which would return 8 as a value.
Hope that this helps,
Kind Regards
Anthony Moore
IT Excellence
DateDiff counts boundaries, in this case the number of times the big
hand is at the twelve between the start and stop times.
Unless this is taken into consideration, its return value may not be
as useful as we would like.
Take someone who works from
#9:01:00 AM#
#5:59:00 PM#
He or she works just two minutes short of nine hours.
But DateDiff("H", #9:01:00 AM#, #5:59:00 PM#) returns 8.
If I were being paid for eight hours for working for almost nine hours
I might think I was being treated unfairly.
I have a little function that could be more accurate than a naked
DateDiff; it is UNTESTED AIR CODE but it might serve as a starting
point for the original poster.
Public Function MyHours@( _
ByVal Time1 As Date, _
ByVal Time2 As Date, _
Optional ByVal RoundTo& = 15)
' RoundTo is a number of minutes
' 15 rounds to nearest quarter of an hour
MyHours = Round(CCur(Abs(DateDiff("n", Time1, Time2))) / RoundTo, 0) *
Round(RoundTo / 60, 2)
End Function
For
#9:01:00 AM#
#5:59:00 PM#
MyHours returns 9.