Formatted dates are strings, not integers. Line "6"
is located after line "11"
.
This would be the most correct way to do this:
First determine what the "first week of the year" means:
$CalendarWeekRule = [System.Globalization.CalendarWeekRule]::FirstDay;
Then determine which day of the week is the first day of the week:
$FirstDayOfWeek = [System.DayOfWeek]::Sunday;
Then you can get the correct week number:
$Today = (Get-Date).Date; $TodayWeek = [cultureinfo]::InvariantCulture.Calendar.GetWeekOfYear($Today, $CalendarWeekRule, $FirstDayOfWeek); $TargetDate = Get-Date -Date "2016-02-10"; $TargetWeek = [cultureinfo]::InvariantCulture.Calendar.GetWeekOfYear($TargetDate, $CalendarWeekRule, $FirstDayOfWeek); if ($TargetWeek -lt $TodayWeek) { $true } else { $false }
Please note that if you want to spend a full week of ISO 8601, itβs a bit more complicated .
source share