Swap the dates if necessary. Subtract off weekend days. Do this by figuring out'how many calendar weeks there are between the dates'and multiplying the difference by two. If rst is Nothing, this call won't subtract any dates.
Swap the dates if necessary. Subtract off weekend days. Do this by figuring out'how many calendar weeks there are between the dates'and multiplying the difference by two. If rst is Nothing, this call won't subtract any dates.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
Swap the dates if necessary. Subtract off weekend days. Do this by figuring out'how many calendar weeks there are between the dates'and multiplying the difference by two. If rst is Nothing, this call won't subtract any dates.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
Function dhCountWorkdays(ByVal dtmStart As Date, _
ByVal dtmEnd As Date, _
Optional rst As Recordset = Nothing, _ Optional strField As String = "") _ As Integer Dim intDays As Integer Dim dtmTemp As Date Dim intSubtract As Integer ' Swap the dates if necessary. If dtmEnd < dtmStart Then dtmTemp = dtmStart dtmStart = dtmEnd dtmEnd = dtmTemp End If ' Get the start and end dates to be weekdays. dtmStart = SkipHolidays(rst, strField, dtmStart, 1) dtmEnd = SkipHolidays(rst, strField, dtmEnd, -1) If dtmStart > dtmEnd Then ' Sorry, no workdays to be had. Just return 0. dhCountWorkDays = 0 Else intDays = dtmEnd - dtmStart + 1 ' Subtract off weekend days. Do this by figuring out ' how many calendar weeks there are between the dates ' and multiplying the difference by two (since there ' are two weekend days for each week). That is, if the ' difference is 0, the two days are in the same week. ' If the difference is 1, then you have two weekend days. intSubtract = (DateDiff("ww", dtmStart, dtmEnd) * 2) ' The answer, finally, is all the weekdays, minus any ' holidays found in the table. ' If rst is Nothing, this call won't subtract any dates. intSubtract = intSubtract + CountHolidays(rst, _ strField, dtmStart, dtmEnd) dhCountWorkdays = intDays - intSubtract End If End Function