Convert datetime to week of year (weeknumber)

This is rather an addition to this closed topic (Convert date to week number), than a real question. But it might help some people.

The idea is I want to create a variable that simply is the week of the year, so an integer between 1 and 53.

The solution posted below still yields an error when you haven’t referred to CultureInfo before.

The full solution should be:

System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(System.DateTime.Now, System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule,System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek)


Thanks stevenvd, Very useful :slight_smile:
Is it possible to have the “firstDayOfWeek” Using the above formula ? Thx in advance

What exactly are you looking for? The date of the first day of the current week?

Thanks Stevenvd, I have already fixed the issue : ```
Get-ItemProperty -Path ‘HKCU:\Control Panel\International’| Select-Object iFirstDayOfWeek

Get-ItemProperty -Path 'HKCU:\Control Panel\International'| Select-Object iFirstDayOfWeek
1 Like