Here is another
Code:
'---------------------------------------------------------------------------------------
' Procedure : NumSpecificDayInMonth
' Author : mellon
' Date : 08-Feb-2018 (from google search)
' Purpose : To get the number of specific weekdays in a month
'
' datThis starting day of the Month in question eg 1-Feb-2018 is #2/1/2018#
' intDay is the weekday you want to count eg 1-sun 2-Mon.....7-Sat (defaults to MOnday)
'---------------------------------------------------------------------------------------
'Public Function NumSpecificDayInMonth(ByVal datThis As Date, _
Optional ByVal intDay As Integer = vbMonday) As Integer
10 datThis = DateAdd("d", 1 - Day(datThis), datThis)
20 intDay = (intDay Mod 7) + 1
30 intDay = WeekDay(datThis, intDay) - 1
40 NumSpecificDayInMonth = DateDiff("d", datThis, DateAdd("m", 1, datThis))
50 NumSpecificDayInMonth = (NumSpecificDayInMonth + intDay) \ 7
End Function
Test for Feb 2018
Code:
?NumSpecificDayInMonth(#2/1/2018#,5) '5 is Thursday (based on Sun=1, Mon=2.....)
4