Convert yyyyMMdd string to date and time using PowerShell

 

How do you convert an input string to a date and time format.


[System.Globalization.CultureInfo]$provider = [System.Globalization.CultureInfo]::InvariantCulture
$sInput = 19991231
$format = "yyyyMMdd"
[ref]$parsed = get-date
[DateTime]::TryParseExact($sInput, $format, $provider, [System.Globalization.DateTimeStyles]::None, $parsed)

$parsed is the returned value.

Leave a Reply

Your email address will not be published. Required fields are marked *