Week numbers in C#
Support for ISO week numbers was added in .NET 5.0.
How to get the week number from a date
To get the ISO week number (1-53) from a System.DateTime instance, use
To get the corresponding four-digit year (e.g. 2023), use
Read more about ISOWeek.GetWeekOfYear() and ISOWeek.GetYear() in the .NET API documentation.
How to get the date from a week number
To get the start time of a week (Monday at midnight), use
System.Globalization.ISOWeek.ToDateTime(year, week, DayOfWeek.Monday)).
year is a 4-digit year (e.g. 2023), and week is an ISO week number (1-53).
Read more about ISOWeek.ToDateTime() in the .NET API documentation.
How to get the number of weeks in a year
To get the number of ISO weeks in a year (i.e. the number of the last week), use
Read more about ISOWeek.GetWeeksInYear() in the .NET API documentation.