by Fabio Resto (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 24th October 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Finds business days between two dates. Works along the same lines as Excel's 'networkdays' function (eg October 1 to October 31 will output 23
Dim FDate As Date
Dim SDate As Date
Dim DaysApart As Integer
Dim Weekends As Integer
DaysApart = 0
Weekends = 0
' this function will show the amount of business days including start date e.g. Oct 1 to Oct 31
' will display 23 business days (works along the same lines as Excel's 'networkdays' function)
FDate = FirstDate
SDate = SecondDate
If SDate < FDate Then
MsgBox "Second date is less than first date.", vbCritical, "Error..." ' second date is less than first date
Exit Function
End If
DaysApart = DateDiff("d", FDate, SDate) + 1 ' + 1 is to include start date
Do Until FDate = SDate
FDate = FDate + 1 ' will loop until dates match
If Format(FDate, "dddd") = "Saturday" Or Format(FDate, "dddd") = "Sunday" Then
Weekends = Weekends + 1 ' checks day and if Sat or Sun, then adds 1
End If
Loop
If Format(FirstDate, "dddd") = "Saturday" Or Format(FirstDate, "dddd") = "Sunday" Then
Weekends = Weekends + 1 ' if start date is weekend day then add one
End If
FindBusDays = DaysApart - Weekends
End Function
No comments have been posted about Finds business days between two dates. Works along the same lines as Excel's 'networkdays' function. Why not be the first to post a comment about Finds business days between two dates. Works along the same lines as Excel's 'networkdays' function.