Это сообщение рассказывает вам, как это сделать на C#. Count number of Mondays in a given date range
Я пропустил код через преобразователь ниже. Не проверял.
Private Shared Function CountDays(day As DayOfWeek, start As DateTime, [end] As DateTime) As Integer
Dim ts As TimeSpan = [end] - start
' Total duration
Dim count As Integer = CInt(Math.Floor(ts.TotalDays/7))
' Number of whole weeks
Dim remainder As Integer = CInt(ts.TotalDays Mod 7)
' Number of remaining days
Dim sinceLastDay As Integer = CInt([end].DayOfWeek - day)
' Number of days since last [day]
If sinceLastDay < 0 Then
sinceLastDay += 7
End If
' Adjust for negative days since last [day]
' If the days in excess of an even week are greater than or equal to the number days since the last [day], then count this one, too.
If remainder >= sinceLastDay Then
count += 1
End If
Return count
End Function
Ваш заголовок говорит «Понедельники в месяц», но ваш текст вопроса спрашивает «сколько понедельников существует между двумя датами». Какой вы хотите? –
эти две даты - начало месяца и конец – Carlos1