For Pure Powershell:
There is a problem with Culture and UICulture
To print the first day of the week in the language of the Culture:
(Get-Culture).DateTimeFormat.DayNames[(Get-Culture).DateTimeFormat.FirstDayOfWeek.value__]
maandag (which is My language AND My starting weekday
(Get-uiCulture).DateTimeFormat.DayNames[(Get-Culture).DateTimeFormat.FirstDayOfWeek.value__]
Monday (which is NOT My language BUT is My starting weekday
(Get-uiCulture).DateTimeFormat.DayNames[(Get-uiCulture).DateTimeFormat.FirstDayOfWeek.value__]
Sunday (which is NOT My language AND NOT My starting weekday
(Get-Culture).DateTimeFormat.DayNames[(Get-uiCulture).DateTimeFormat.FirstDayOfWeek.value__]
zondag (which is My language AND NOT My starting weekday
Then there is the problem of weeknumbers not working to ISO8601 standard.
Date 2012-12-31 should be week 1 but it gives 53.
So you would have to implement some sort of solution to that.
(Get-Culture).Calendar.GetWeekOfYear((Get-Date).AddDays(3*([int](Get-Date).DayOfWeek -in (1,2,3))), ((Get-Culture).DateTimeFormat.CalendarWeekRule), ((Get-Culture).DateTimeFormat.FirstDayOfWeek))
For testing:
(Get-Culture).Calendar.GetWeekOfYear((Get-Date('2013-01-01')).AddDays(3*([int](Get-Date('2013-01-01')).DayOfWeek -in (1,2,3))), ((Get-Culture).DateTimeFormat.CalendarWeekRule), ((Get-Culture).DateTimeFormat.FirstDayOfWeek))
(Get-Culture).Calendar.GetWeekOfYear((Get-Date('2012-12-31')).AddDays(3*([int](Get-Date('2012-12-31')).DayOfWeek -in (1,2,3))), ((Get-Culture).DateTimeFormat.CalendarWeekRule), ((Get-Culture).DateTimeFormat.FirstDayOfWeek))
(Get-Culture).Calendar.GetWeekOfYear((Get-Date('2012-12-30')).AddDays(3*([int](Get-Date('2012-12-30')).DayOfWeek -in (1,2,3))), ((Get-Culture).DateTimeFormat.CalendarWeekRule), ((Get-Culture).DateTimeFormat.FirstDayOfWeek))
These should give 1,1,52(correct) instead of 1,53,52(incorrect).
Or (UICulture related version)
(Get-UICulture).Calendar.GetWeekOfYear((Get-Date).AddDays(3*([int](Get-Date).DayOfWeek -in (0,1,2))), ((Get-UICulture).DateTimeFormat.CalendarWeekRule), ((Get-UICulture).DateTimeFormat.FirstDayOfWeek))
For testing:
(Get-UICulture).Calendar.GetWeekOfYear((Get-Date('2013-01-01')).AddDays(3*([int](Get-Date('2013-01-01')).DayOfWeek -in (0,1,2))), ((Get-UICulture).DateTimeFormat.CalendarWeekRule), ((Get-UICulture).DateTimeFormat.FirstDayOfWeek))
(Get-UICulture).Calendar.GetWeekOfYear((Get-Date('2012-12-31')).AddDays(3*([int](Get-Date('2012-12-31')).DayOfWeek -in (0,1,2))), ((Get-UICulture).DateTimeFormat.CalendarWeekRule), ((Get-UICulture).DateTimeFormat.FirstDayOfWeek))
(Get-UICulture).Calendar.GetWeekOfYear((Get-Date('2012-12-30')).AddDays(3*([int](Get-Date('2012-12-30')).DayOfWeek -in (0,1,2))), ((Get-UICulture).DateTimeFormat.CalendarWeekRule), ((Get-UICulture).DateTimeFormat.FirstDayOfWeek))
(Get-UICulture).Calendar.GetWeekOfYear((Get-Date('2012-12-29')).AddDays(3*([int](Get-Date('2012-12-29')).DayOfWeek -in (0,1,2))), ((Get-UICulture).DateTimeFormat.CalendarWeekRule), ((Get-UICulture).DateTimeFormat.FirstDayOfWeek))
These should give 1,1,1,52(correct) instead of 1,53,53,52(incorrect).
Because starting weekday is Sunday.
You can test the incorrect result by replacing 3* with 0*.
Made it into a function you can give it no parameter a date or a string:
function Get-ISO8601Week {
Param(
$getISO8601Week = $(Get-Date)
)
If ($getISO8601Week.GetType() -eq [string]){
$getISO8601Week = (Get-Date($getISO8601Week))
}
$getCulture = Get-Culture
($getCulture).Calendar.GetWeekOfYear(
$getISO8601Week.AddDays(
3*([int]$getISO8601Week.DayOfWeek -in (0,1,2))
), ($getCulture.DateTimeFormat.CalendarWeekRule
), ($getCulture.DateTimeFormat.FirstDayOfWeek
)
)
}
Get-ISO8601Week $(Get-Date('2012-12-31'))
1
Get-ISO8601Week (Get-Date('2012-12-31'))
1
Get-ISO8601Week '2012-12-31'
1
When I wrote this:
Get-ISO8601Week
4