0

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.

1
  • what format pattern does R give? Commented Oct 14, 2021 at 10:04

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.