VB.NET How many weekdays between two dates

Here is a quick way to find out how many times a particular day of the week occurs between two dates.
For example, how many sundays between two dates.

    Protected Function findWeekDays(ByVal startDate As Date, ByVal endDate As Date, ByVal DayOfWeek As Microsoft.VisualBasic.FirstDayOfWeek) As Integer
        Dim Resp As Integer
        Resp = DateDiff("ww", startDate, endDate, DayOfWeek)
        If Weekday(startDate) = DayOfWeek Then Resp += 1
        Return Resp
    End Function

2 thoughts on “VB.NET How many weekdays between two dates”

  1. Thanks! I found this in C# but no one had a VB version. Worked great in Reporting Services. You saved me a call to the database.

Comments are closed.