Calculating time

IanT

Registered User.
Local time
Today, 21:37
Joined
Nov 30, 2001
Messages
191
I need to calculate holiday taken by using time, using this data:
StartDate StartTime
22-03 08:00
EndDate Endtime
25-03 16:00

Allowing for weekends.

answer............15:00

Can anyone help...........
 
Function NumberOfHours(dStart As Date, dEnd As Date) As Double
Dim dbDIF As Double
Dim dLoop As Date
Dim iCount As Integer
Const iMIN As Integer = 15

For dLoop = dStart To dEnd Step DateAdd("n", iMIN, dLoop)
If Weekday(dLoop) > vbSunday And Weekday(dLoop) < vbSaturday Then
'If DatePart("H", dLoop) = 8 Then Stop
If Format(dLoop, "hhnn") > Format("8:00 AM", "hhnn") And _
Format(dLoop, "hhnn") <= Format("12:00 PM", "hhnn") Then
iCount = iCount + iMIN
ElseIf Format(dLoop, "hhnn") > Format("1:00 PM", "hhnn") And _
Format(dLoop, "hhnn") <= Format("5:00 PM", "hhnn") Then
iCount = iCount + iMIN
End If
End If
Next

NumberOfHours = iCount / 60

End Function

Call Example from Debug Window
?NumberOfHours(#3/22/2002 08:00#,#3/25/2002 16:00#)
 

Users who are viewing this thread

Back
Top Bottom