G
Guest
Is there a way programmatically to count how many Mondays there are for a
given Month. For example, January 2005 has 5-Mondays, 4-Tuesdays, etc.
given Month. For example, January 2005 has 5-Mondays, 4-Tuesdays, etc.
Graham R Seach said:Not exhaustively tested, but it seems to work:
Public Function CountOfDayInMonth( _
dte As Date, iDay As VbDayOfWeek) As Integer
'Calculates the number of times the specified
'day of the week occurs within the specified
'month.
'
'dte is specified as a date because February
'has an extra day in leap years.
'
'INPUTS:
' dte = a date in the month/year in question.
' iDay = the day of the week you to count.
'
'RETURN VALUE:
' Integer value.
'
Dim dteFirst As Date
Dim dteLast As Date
'Get the date of the first specified day in the month.
dteFirst = DateSerial(Year(dte), Month(dte), 0) + _
(8 - Weekday(DateSerial(Year(dte), Month(dte), 0), iDay))
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.