String to DateTime conversion in PowerShell String to DateTime conversion in PowerShell powershell powershell

String to DateTime conversion in PowerShell


You can use the ParseExact method:

[datetime]::ParseExact('24122014_022257','ddMMyyyy_HHmmss',$null)Wednesday, December 24, 2014 2:22:57 AM


ParseExact will do just that. You can specify custom datetime format in second parameter. You can leave third parameter as null, or specify a culture to use (it may matter if you're importing files that were generated from system with different time zone).

$usdate="24122014_022257"[datetime]::ParseExact($usdate,"ddMMyyyy_HHmmss", [System.Globalization.CultureInfo]::CurrentCulture)


get-date 24122014022257

Wednesday, December 24, 2014 2:22:57 AM