Hi,
I am trying to convert a odd date/time string with the format “MMM dd, HH:mm zzz” into a [datetime] datatype, so I can convert it to my time zone; and I am struggling with ParseExtract.
The string (example “Feb 14, 14:37 PST”) is helpfully provided from the data feed without the year; but it is the current year.
I have tried pre-pending the current year into the input string; but that hasn’t worked.
This is where I am at code wise:
$InputString = "Feb 14, 14:37 PST"
$CurrentYear = Get-Date -UFormat %Y
$InputStringWithYear = $CurrentYear + " " + $InputString
$OutputDateTime = [datetime]::ParseExact($InputStringWithYear, "yyyy MMM dd, HH:mm zzz", $null)
and this is the error:
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
At line:4 char:1
+ $OutputDateTime = [datetime]::ParseExact($InputStringWithYear, "yyyy ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
Would appreciate it if anyone can help or give me an alternative approach to try.
I thought this would be straightforward
Cheers
Pin.