- Week 1 is defined as the first week of a Gregorian year to contain a Thursday
- All ISO weeks start on a Monday and the days are numbered 1=Monday, 2=Tuesday, 3= Wednesday, ... 7 = Sunday
- Any January dates prior to start of week 1 will be numbered as if they were last week of previous year
- Years normally have 52 weeks but it is possible to have 53 ISO Weeks
- ISO Week dates are normally written in the format yyyy-Www-d where yyyy=ISO Year, -W is "-W", - is "-" and d = day-of-week (1=Mon 7=Sun)
- You may encounter non-standard week number systems (especially in spreadsheets,) this page relates to ISO-8601 compliant dates
Get ISO-Week Date relating to a Gregorian Date
Public Shared Function Gregorian_To_IsoWeek(date_Greg) As ISO_Week
Dim ISO As ISO_Week
ISO.yyyy = ISOWeek.GetYear(date_Greg)
ISO.ww = ISOWeek.GetWeekOfYear(date_Greg)
ISO.d = CInt(date_Greg.dayOfweek)
If ISO.d = 0 Then ISO.d = 7 ' Sunday=0 in .Net Sunday=7 in ISO-Week
ISO.IsoWeekDate = ISO.yyyy.ToString("0000") & "-W" & ISO.ww.ToString("00") & "-" & ISO.d.ToString("0")
Return ISO
End Function
Public Structure ISO_Week
Dim yyyy As Integer
Dim ww As Integer
Dim d As Integer
Dim IsoWeekDate As String
End Structure
Get Gregorian Date relating to an ISO-Week Date
Public Shared Function IsoWeek_To_Gregorian(ISO_yyyy As Integer, ISO_ww As Integer, ISO_d As Integer) As Date
Dim date_Greg As Date = ISOWeek.ToDateTime(ISO_yyyy, ISO_ww, ISO_d)
' fix time as midday - this avoids rare but obscure issues with clock changes etc.
Return New Date(date_Greg.Year, date_Greg.Month, date_Greg.Day, 12, 0, 0, 0, 0)
End Function
DigitalDan.co.uk