How to convert Python’s .isoformat() string back into datetime object [duplicate]

Python 3.7+

As of Python 3.7 there is a method datetime.fromisoformat() which is exactly the reverse for isoformat().

Older Python

If you have older Python, then this is the current best “solution” to this question:

pip install python-dateutil

Then…

import datetime
import dateutil

def getDateTimeFromISO8601String(s):
    d = dateutil.parser.parse(s)
    return d

Leave a Comment