I am new to Powershell (general new to coding). What I am trying to do is: A user should be able to input a date. Powershell should echo the amount of days left till next year's December 6th.
Example: Input is 20/01/2017 and the output should be the amount of days left till 06/12/2018.
It works completely fine when I do $days = New-TimeSpan -End (Get-Date -Year $inputdate3 -Month 12 -day 6) but I want to replace this cmdlet with my string.
My code is:
$inputdate = Read-Host "Please enter the current date [DD/MM/YYYY] :"
$inputdate = [DateTime]::Parse($inputdate)
$inputdate2 = $inputdate.AddYears(1)
$inputdate3 = $inputdate2.Year
$days = New-TimeSpan -Start $inputdate -End $inputdate3 -Month 12 -Day 6 | ForEach-Object {$_.days}
echo "$days"
But I get this error:
New-TimeSpan : Parameter set cannot be resolved using the specified named parameters. At C:\Users\Asli\Desktop\O2P2_Version1_2.ps1:96 char:13 + $days = New-TimeSpan -Start $inputdate -End $inputdate3 -Month 12 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-TimeSpan], ParameterBindingException + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.NewTimeSpanCommand
-Startand-End, you cannot use-Monthand-Dayin the same command. - AdminOfThings