Question : How to get the calendar date based on a weekday

I am looking to genarate a list of all dates that fall on Monday for a given year.

Ie , jan 4, Jan 11, Jan 18, Jan 25 etc for the calendar year 2010.

Answer : How to get the calendar date based on a weekday

This is another alternative.
 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        CalDisplay(2010, WeekdayArrange.Monday)
    End Sub

    Enum WeekdayArrange
        Sunday = 1
        Monday = 2
        Tuesday = 3
        Wednesday = 4
        Thursday = 5
        Friday = 6
        Saturday = 7
    End Enum

    Sub CalDisplay(ByVal intYear As Integer, ByVal intDay As WeekdayArrange)
        Dim intTotalDays As Integer
        intTotalDays = DateDiff(DateInterval.Day, CDate(intYear & "-1-1"), CDate(intYear & "-12-31"))

        Dim strDays As String = ""
        Dim dtCurr As Date = CDate(intYear & "-1-1")

        For i As Integer = 1 To intTotalDays Step 1

            If intDay = Weekday(dtCurr, Microsoft.VisualBasic.FirstDayOfWeek.Sunday) Then
                strDays &= MonthName(Month(dtCurr), True) & " " & Day(dtCurr) & "
"
            End If

            dtCurr = dtCurr.AddDays(1)
        Next

        Response.Write(strDays)

    End Sub
Random Solutions  
 
programming4us programming4us