Using ISO timestamp in Flask-SQLAlchemy
You need to convert the string into a Python datetime object, which you can do using time.strptime
:
record.date = time.strptime(mytime, "%Y-%m-%dT%H:%M:%SZ")
Then you can safely set it on your instance and commit it.
To get it back in the same format, use time.strftime
on the other side:
time.strftime("%Y-%m-%dT%H:%M:%SZ", record.date)
And of course remember to watch out that the order of the arguments is different between strptime
and strftime
:)
If you need to change/update the format, see time.strftime
here : https://docs.python.org/2/library/time.html