0

I have the follow code, but having trouble removing the Z at the end. The time format looks like this 2020-07-28T15:47:36.165310258Z

from datetime import datetime
datetime.strptime(f[a]['Created On'], "%Y-%m-%dT%H:%M:%S.%f")

When using the %f, I noticed that it is only able to the next 6 digit. Is there any way to make it take more? This is the error that I am getting (MISSING) ValueError: unconverted data remains: 258Z

What is the best way to remove the Z and have it just return the date?

1
  • strptime isn't great for dealing with ISO8601 formatted strings. I'd suggest using arrow or dateutil instead. Commented Aug 4, 2020 at 23:31

1 Answer 1

1

Was able to get around the issue by just moving the last 4 characters from the string and then using datetime.strptime on it.

datetime.strptime(f[a]['Created On'][:-4], "%Y-%m-%dT%H:%M:%S.%f")

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.