Python Forum

Full Version: Sqlalchemy accepting ISO 8601
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a csv im trying to upload to a database.

Database uses flask - sqlalchemy.

Collects row from csv.
date_time_store = row['date_time']
Uploads row
query = tintin_store(date_time = date_time_store
Cell is formatted like so
 date_time = db.Column(db.DATETIME, nullable=False, primary_key=True)
My timezone in the csv is in ISO 8601: e.g. 2018-07-27T11:19:40+01:00

the cell accepts date time in the 'standard' form : 2018/07/27 11:19:40

I can not find an easy way to convert the ISO 8601 into a format my sqlalchemy table will accept. I dont really care about UTC in this project so if needs to be removed then it can be, but the data entry format has to be ISO 8601 and i would ideally like to at least keep the utc saved somewhere. Even if this means introducing a new column and inserting it as a string in there.

So far i have tried: 
date_time_store= dateutil.parser.parse(date_time_store)
date_time_store= dateutil.parser.parse(date_time_store).timetuple()
date_time_store= time.strptime(date_time_store, "%Y-%m-%dT%H:%M:%S")
date_time_store= time.strptime(date_time_store, "%Y-%m-%dT%H:%M:%S%z")
date_time_store= time.strptime(date_time_store, "%Y-%m-%dT%H:%M:%S%Z")
All of which have failed if required can probably recode to get the tracebacks of each failure. Anyone know of a solution to my somewhat basic problem. ?