Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to display the week's no based on the year. The week no must be display based on the year. the week count should come based on the given year only.

Now, i am displaying continuous sequence week no. but, i want to split and display based on the year week count no.

pls. help.

the code is below.
------------------
Imports System.Globalization
Partial Class CountWeek
    Inherits System.Web.UI.Page
    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 = "2011"
        Dim ToYear As Integer = "2020"
        Dim firstDayOfYear As New DateTime(FromYr, 1, 3)
        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
        'Dim SelectedWeek As Integer
        While tempDate <= lastDayOfYear
            weekNumber += 1
            tempString = weekNumber.ToString() & " | "
            tempString += tempDate.ToShortDateString() & " - "
            'Dim Midnight_for_the_Current As Date = DateAdd(DateInterval.Second, -3, DateAdd(DateInterval.Year, DateDiff(DateInterval.Year, Date.MinValue, firstDayOfYear), Date.MinValue))
            ' If Midnight_for_the_Current Then
            'If DateDiff(DateInterval.DayOfYear, tempDate, lastDayOfYear) = False Then
            tempDate = GetLastDayOfWeek(tempDate, lastDayOfYear)
            tempString += tempDate.ToShortDateString()
            weekList.Add(tempString)
            tempDate = tempDate.AddDays(1)
            ' End If
        End While
        'SelectedWeek = DatePart(DateInterval.WeekOfYear, Now.Date, Microsoft.VisualBasic.FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFullWeek)
        drpWeeknos.DataSource = weekList
        drpWeeknos.DataBind()
    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
End Class



pls. give me the solution in vb.net only.

Regards,
Ganesh.S
Posted
Updated 26-Jun-11 20:14pm
v2

1 solution

Use following in the loop,
Dim WeekNumber As Integer = DatePart(DateInterval.WeekOfYear, tempDate, FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFourDays)
 
Share this answer
 

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