I tried both subs to get the number of the week of the year. But the result of the following dates ist always week 5. The reason seems to be the start of the week = sunday, and not monday.
How can I set the first day of the week in one of the following subs?
Private Sub GetWeekNumber(DateTicks As Long) As Int
Dim psCurrFmt As String = DateTime.DateFormat
DateTime.DateFormat = "w"
Dim piCurrentWeek As Int = DateTime.Date(DateTicks)
DateTime.DateFormat = psCurrFmt
Return piCurrentWeek
End Sub
'-or-
Sub GetWeekNumber(ticks As Long) As Int
Dim offset As Int = DateTime.GetDayOfWeek(DateUtils.SetDate( _
DateTime.GetYear(ticks), 1, 1)) - 1
Return Floor((DateTime.GetDayOfYear(ticks) -1 + offset) / 7) + 1
End Sub
Sub GetWeekNumberStartingFromMonday (ticks As Long) As Int
Dim firstdayOffset As Int = DateTime.GetDayOfWeek(DateUtils.SetDate( _
DateTime.GetYear(ticks), 1, 1)) - 2
If firstdayOffset < 0 Then firstdayOffset = firstdayOffset + 7
Return Floor((DateTime.GetDayOfYear(ticks) - 1 + firstdayOffset) / 7) + 1
End Sub