I have a date which I obtain from an API. It is in the form of 2015-01-01T15:04:23Z
.
How can I accept this date into a model using Flask-SQLAlchemy?
So far I have tried,
date = db.Column(db.DateTime)
and
date = db.Column(db.DateTime(timezone=True))
which gives me the error
StatementError: (exceptions.TypeError) SQLite DateTime type only accepts Python datetime and date objects as input.
Also, when I retrieve it using a get
, I need it to be in the exact same format.
The dateutil
python module parses it well but when I retrieve it from the table, I need to get 2015-01-01T15:04:23Z
.
>>> from dateutil.parser import parse
>>> parse('2015-01-01T15:04:23Z')
datetime.datetime(2015, 1, 1, 15, 4, 23, tzinfo=tzutc())