I'm running into a weird issue where I'm trying to parse an array of the following strings, which have been given the variable $DatesUnformatted
:
2020-02-28T05:29:00Z
2020-02-28T04:52:00Z
2020-02-28T04:52:00Z
2020-02-27T17:01:00Z
2020-02-27T17:01:00Z
2020-02-27T17:01:00Z
2020-02-27T17:01:00Z
...to a time format (hh:mm tt
) using [DateTime]::ParseExact()
.
My script looks like something like this:
foreach ($DateUnformatted in $DatesUnformatted)
{
$DateFormatted = [datetime]::parseexact($DateUnformatted, 'yyyy-MM-ddThh:mm:ssZ',$null).ToString('hh:mm tt')
echo "Converting $DateUnformatted to $DateFormatted"
}
And here's the output:
Converting 2020-02-28T05:29:00Z to 12:29 AM
Converting 2020-02-28T04:52:00Z to 11:52 PM
Converting 2020-02-28T04:52:00Z to 11:52 PM
Converting 2020-02-27T17:01:00Z to 11:52 PM
Converting 2020-02-27T17:01:00Z to 11:52 PM
Converting 2020-02-27T17:01:00Z to 11:52 PM
Converting 2020-02-27T17:01:00Z to 11:52 PM
It seems like it's only converting the first few entries then just repeating one until the end of the loop. Any ideas?