1

I have the following date in python, as a string which I want to convert to datetime

I tried using strptime function, but due to the format with decimals and a marginal value, it keeps failing. Any idea on how to convert it? The date string structure is like this example: 2022-02-08 17:12:35.667000+00:00

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
  • 3
    Does this answer your question? [How do I parse an ISO 8601-formatted date?](https://stackoverflow.com/questions/127803/how-do-i-parse-an-iso-8601-formatted-date) – FObersteiner Feb 19 '22 at 16:58
  • 1
    Did you forget to post your code? It would help if we could see the format specifier you're using – DarkKnight Feb 19 '22 at 17:02

1 Answers1

0

The dateutil module has something just for this. You can use its parser to create a datetime object from a string like this.

from dateutil import parser

date_obj = parser.parse("2022-02-08 17:12:35.667000+00:00")

EDIT:

I don't believe that this is a default python library, so you can type this code into the terminal to install it with pip: pip install python-dateutil

Timmy Diehl
  • 409
  • 3
  • 16