Пояснение Powershell Get-Date:
-Day
Specifies the day of the month that is displayed. Enter a value from 1 to 31. >The default is the current day.
If you specify a value that is greater than the number of days in the month, >PowerShell adds the number of days to the month and displays the result. For >example, "Get-Date -Month 2 -Day 31" displays "March 3", not "February 31".
Будет ли это перенесено на новый год, или мне нужно будет настроить код для определения нового года, если дата в конечном итоге преобразуется в January 1?





Нет, он не будет перенесен, потому что в декабре 31 день, и все, что больше 31 дня, является исключением.
Get-Date -Month 2 -Day 32
Результат:
Get-Date : Cannot validate argument on parameter 'Day'. The 32 argument is greater than the maximum allowed range of 31. Supply an argument that is less than or equal to 31 and then try the command again.
At line:1 char:24
+ get-date -month 2 -day 32
+
+ CategoryInfo : InvalidData: (:) [Get-Date], ParameterBindingValidationException
+ FullyQualifiedErrorId :
ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetDateCommand
То же самое для 12-го месяца:
Get-Date -Month 12 -Day 32
Результат
Get-Date : Cannot validate argument on parameter 'Day'. The 32 argument is greater than the maximum allowed range of 31. Supply an argument that is less than or equal to 31 and then try the command again.
At line:1 char:24
+ get-date -month 2 -day 32
+
+ CategoryInfo : InvalidData: (:) [Get-Date], ParameterBindingValidationException
+ FullyQualifiedErrorId :
ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetDateCommand
@JacobKucinic - вы можете получить количество дней в любом месяце, таким образом ... [datetime]::DaysInMonth(2018, 12). [ухмылка]
@JacobKucinic Думаю, мне нужно просто систематически корректировать каждое значение в течение года. Не изобретайте велосипед заново. Он уже здесь: (Get-Date -Month 12 -Day 31) + (New-TimeSpan -Days 1).
Интересный. Я даже не думал о том, что добавление дня переместит его в 32, что не имеет значения. Думаю, мне нужно просто систематически корректировать каждое значение в течение года. Спасибо.