Python >= 3.7
to convert YYYY-MM-DD string to datetime object, datetime.fromisoformat
could be used.
from datetime import datetimedate_string = "2012-12-12 10:10:10"print (datetime.fromisoformat(date_string))2012-12-12 10:10:10
Caution from the docs:
This does not support parsing arbitrary ISO 8601 strings - it is only intended as the inverse operation of
datetime.isoformat()
. A more full-featured ISO 8601 parser,dateutil.parser.isoparse
is available in the third-party packagedateutil
.