It is easier to use "w" as
formatsetting. And, btw, much less code needed
DateTime.Dateformat = "w"
Log("Week="&DateTime.Date(DateTime.now))
or you can write (okok, i already did
) a sub for it and use this sub.
Sub GetWeekOfYear(dt As Long) As Int
' store old timeformat pattern
Dim oldsetting As String = DateTime.TimeFormat
' set temporary timeformat pattern
DateTime.TimeFormat = "w"
' Get weekno
Dim weekno As Int
weekno = DateTime.Date(dt)
' restore old timeformat pattern
DateTime.TimeFormat = oldsetting
' return weekno as int
Return weekno
End Sub
Log("WeekNo = "&GetWeekOfYear(DateTime.now))