我有以下代码,该代码从给定的2个日期计算营业时间。开始时间是上午9点,结束时间是5.30pm。但是,如何合并可以防止包括周末在内的规则?我在这里有这样的想法:/
Function ElapsedBusinessMinutes(StartDateTime As Date, StopDateTime As Date) As Single
Dim dteAdjStart As Date
Dim lngElapsedMinutes As Long
Dim lngMinutesInWorkDay As Long
lngMinutesInWorkDay = 510
dteAdjStart = TimeValue(StartDateTime)
If dteAdjStart > #5:30:00 PM# Then
dteAdjStart = TimeSerial(7, Minute(StartDateTime), Second(StartDateTime))
lngElapsedMinutes = DateDiff("d", StartDateTime, StopDateTime - 1) * lngMinutesInWorkDay
Else
lngElapsedMinutes = DateDiff("d", StartDateTime, StopDateTime) * lngMinutesInWorkDay
End If
ElapsedBusinessMinutes = lngElapsedMinutes + DateDiff("n", dteAdjStart, TimeValue(StopDateTime))
End Function