I'm trying to use powershell to convert a string that contains RFC 2822 formatted dates into another format. Right now I'm getting an error saying my string was not recognized as a valid DateTime.
Write-Host ([Datetime]::ParseExact('Thu Oct 07 09:23:26 UTC 2021', '[R][1]', $null)).ToString("yyyyMMdd")
I'm not sure what I'm doing wrong.
CodePudding user response:
The R
standard datetime format string specifier does not describe the format you've supplied.
You're gonna need a custom format string:
[Datetime]::ParseExact('Thu Oct 07 09:23:26 UTC 2021', 'ddd MMM dd HH:mm:ss UTC yyyy', $null)