GirishDhruva
Active Member
- Joined
- Mar 26, 2019
- Messages
- 308
Hi Everyone,
Here i am trying to count number of weekends that are available in a particular month excluding 2nd and 4th Saturday
I have the below code to check all the Saturdays and Sundays that are available between two dates but i need to exclude 2nd and 4th Saturday between those two given dates
Regards
Dhruva
Here i am trying to count number of weekends that are available in a particular month excluding 2nd and 4th Saturday
I have the below code to check all the Saturdays and Sundays that are available between two dates but i need to exclude 2nd and 4th Saturday between those two given dates
Code:
Public Function CountWeekendDays(Date1 As Date, Date2 As Date) As Long Dim StartDate As Date, EndDate As Date, _
WeekendDays As Long, i As Long
If Date1 > Date2 Then
StartDate = Date2
EndDate = Date1
Else
StartDate = Date1
EndDate = Date2
End If
WeekendDays = 0
For i = 0 To DateDiff("d", StartDate, EndDate)
Select Case Weekday(DateAdd("d", i, StartDate))
Case 1, 7
WeekendDays = WeekendDays + 1
End Select
Next i
CountWeekendDays = WeekendDays
End Function
dates = CountWeekendDays("8/7/2019", "31/7/2019")
MsgBox ("Number of weekends are" & dates)
Regards
Dhruva