Reputation: 115
Powershell Get-Date Explanation:
-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".
Will this roll over into new year as well, or do I have to adjust code to detect new year if the date ends up transforming into January 1
?
Upvotes: 1
Views: 2151
Reputation: 415971
No, it will not roll over, because December has 31 days and anything higher than 31 is an exception.
Get-Date -Month 2 -Day 32
Result:
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
Same for month 12:
Get-Date -Month 12 -Day 32
Result
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
Upvotes: 4