datetime from string in Python, best-guessing string format

Use the dateutil library.

I was already using dateutil as an indispensable lib for handling timezones
(See Convert UTC datetime string to local datetime and How do I convert local time to UTC in Python?)

And I’ve just realized it has date parsing support:

import dateutil.parser
yourdate = dateutil.parser.parse(datestring)

(See also How do I translate a ISO 8601 datetime string into a Python datetime object?)

Leave a Comment