Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I want to split the week no year wise. for example if 2006 has 52 weeks it will display 1 to 52. if 2007 has 53 weeks again it will split 1 to 53 like that.

now, i am displaying all the weeks without split for the diff. year.

Code is below.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Assumes that week range is from Sunday - Saturday 
        Dim FromYr As Integer = "2006"
        Dim ToYear As Integer = "2015"
        Dim firstDayOfYear As New DateTime(FromYr, 1, 1)
        Dim lastDayOfYear As New DateTime(ToYear, 12, 31)
        Dim weekNumber As Integer = 0
        Dim weekList As New List(Of String)()
        Dim tempDate As DateTime = firstDayOfYear
        Dim tempString As String = String.Empty
        While tempDate <= lastDayOfYear
            weekNumber += 1
            tempString = weekNumber.ToString() & " | "
            tempString += tempDate.ToShortDateString() & " - "
            tempDate = GetLastDayOfWeek(tempDate, lastDayOfYear)
            tempString += tempDate.ToShortDateString()
            tempDate = tempDate.AddDays(1)
        End While
        drpWeeknos.DataSource = weekList

    End Sub
    Private Function GetLastDayOfWeek(ByVal firstDayOfWeek As DateTime, ByVal lastDayOfYear As DateTime) As DateTime
        Dim lastDayOfWeek As DateTime = firstDayOfWeek
        If firstDayOfWeek.DayOfWeek = DayOfWeek.Monday Then
            lastDayOfWeek = firstDayOfWeek.AddDays(6)
        End If
        If firstDayOfWeek.DayOfWeek = DayOfWeek.Tuesday Then
            lastDayOfWeek = firstDayOfWeek.AddDays(5)
        End If
        If firstDayOfWeek.DayOfWeek = DayOfWeek.Wednesday Then
            lastDayOfWeek = firstDayOfWeek.AddDays(4)
        End If
        If firstDayOfWeek.DayOfWeek = DayOfWeek.Thursday Then
            lastDayOfWeek = firstDayOfWeek.AddDays(3)
        End If
        If firstDayOfWeek.DayOfWeek = DayOfWeek.Friday Then
            lastDayOfWeek = firstDayOfWeek.AddDays(2)
        End If
        If firstDayOfWeek.DayOfWeek = DayOfWeek.Saturday Then
            lastDayOfWeek = firstDayOfWeek.AddDays(1)
        End If
        If firstDayOfWeek.DayOfWeek = DayOfWeek.Sunday Then
            lastDayOfWeek = firstDayOfWeek
        End If
        If lastDayOfWeek > lastDayOfYear Then
            lastDayOfWeek = lastDayOfYear
        End If
        Return lastDayOfWeek
    End Function

Pls. help. Dropdown display as week no wise for every year.

Updated 25-Jun-11 4:54am

Seems to be you are posting the same question in different ways.

Take a look at my solution here
i want to get all the list of week[^]

You can use the same method with first day of the year to last day of the year. The diff will give the number of workweeks in an year.

Calendar.Getweekofyear is the method.
Share this answer
Manfred Rudolf Bihy 25-Jun-11 13:17pm    
Correct :)! 5+
I posted an elaborated example on how to find the weeks between two dates to your other question here: i want to get all the list of week[^].

Best Regards,

Share this answer
Espen Harlinn 25-Jun-11 13:19pm    
Here comes the other 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900