Snepnet, smid et svar.
Jeg lavede en kombi af deit svar fra 11/04-2007 17:11:18 og
http://konsulent.sandelien.no/VB_help/Week/Og hvis andre som mig ikke har styr på C# kan jeg anbefale:
http://authors.aspalliance.com/aldotnet/examples/translate.aspx(Virker bedst i Internet explorer...Grrrr)
Her er mit resultat - hvis andre kunne have gavn af det:
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
e.Cell.ToolTip = "Week: " & WeekNumber_Entire4DayWeekRule(e.Day.Date).ToString()
End Sub
Private Function WeekNumber_Entire4DayWeekRule(ByVal [date] As DateTime) As Integer
' In this scenario the first day of the week is monday,
' and the week rule states that:
' [...] the first calendar week of a year is the one
' that includes the first Thursday of that year and
' [...] the last calendar week of a calendar year is
' the week immediately preceding the first
' calendar week of the next year.
' The first week of the year may thus start in the
' preceding year
Const JAN As Integer = 1
Const DEC As Integer = 12
Const LASTDAYOFDEC As Integer = 31
Const FIRSTDAYOFJAN As Integer = 1
Const THURSDAY As Integer = 4
Dim ThursdayFlag As Boolean = False
' Get the day number since the beginning of the year
Dim DayOfYear As Integer = [date].DayOfYear
' Get the numeric weekday of the first day of the
' year (using sunday as FirstDay)
Dim StartWeekDayOfYear As Integer = CInt(New DateTime([date].Year, JAN, FIRSTDAYOFJAN).DayOfWeek)
Dim EndWeekDayOfYear As Integer = CInt(New DateTime([date].Year, DEC, LASTDAYOFDEC).DayOfWeek)
' Compensate for the fact that we are using monday
' as the first day of the week
If StartWeekDayOfYear = 0 Then
StartWeekDayOfYear = 7
End If
If EndWeekDayOfYear = 0 Then
EndWeekDayOfYear = 7
End If
' Calculate the number of days in the first and last week
Dim DaysInFirstWeek As Integer = 8 - StartWeekDayOfYear
Dim DaysInLastWeek As Integer = 8 - EndWeekDayOfYear
' If the year either starts or ends on a thursday it will have a 53rd week
If StartWeekDayOfYear = THURSDAY Or EndWeekDayOfYear = THURSDAY Then
ThursdayFlag = True
End If
' We begin by calculating the number of FULL weeks between the start of the year and
' our date. The number is rounded up, so the smallest possible value is 0.
Dim FullWeeks As Integer = CInt(Math.Ceiling(((DayOfYear - DaysInFirstWeek) / 7.0)))
Dim WeekNumber As Integer = FullWeeks
' If the first week of the year has at least four days, then the actual week number for our date
' can be incremented by one.
If DaysInFirstWeek >= THURSDAY Then
WeekNumber = WeekNumber + 1
End If
' If week number is larger than week 52 (and the year doesn't either start or end on a thursday)
' then the correct week number is 1.
If WeekNumber > 52 And Not ThursdayFlag Then
WeekNumber = 1
End If
' If week number is still 0, it means that we are trying to evaluate the week number for a
' week that belongs in the previous year (since that week has 3 days or less in our date's year).
' We therefore make a recursive call using the last day of the previous year.
If WeekNumber = 0 Then
WeekNumber = WeekNumber_Entire4DayWeekRule(New DateTime([date].Year - 1, DEC, LASTDAYOFDEC))
End If
Return WeekNumber
End Function 'WeekNumber_Entire4DayWeekRule