I have a CSV with a 'datetime' column in this format- "11/13/2022 4:30:00 PM". How do I convert that string to a [datetime] type?
I apologize Im having a tough time with this one.
$CSV = Import-Csv "this.csv"
$formattedcsv = $CSV | Select-Object *, @{
Name = 'DateTime'
Expression = {
(("MM/dd/yyyy HH:mm") -as [datetime])
}
}
Expression = {[datetime]::ParseExact($_.datetime, "mm/dd/yyyy HH:mm", [cultureinfo]::CurrentCulture)}MM(lowercase is for minutes) and [2] the example shows there is only one Hour digit (12-hour clock, so that needs to beh, notHH24-hour clock) plus [3] it uses AM/PM designator you did not includeimport-csv this.csv | % { $_.Datetime = [datetime]$_.Datetime; $_ }