I'm using the sqlite3 module in Python 2.6.4 to store a datetime in a SQLite database. Inserting it is very easy, because sqlite automatically converts the date to a string. The problem is, when reading it it comes back as a string, but I need to reconstruct the original datetime object. How do I do this?
Python – How to read datetime back from sqlite as a datetime instead of string in Python
datetimepythonsqlite
Related Topic
- Python – How to safely create a nested directory in Python
- Python – How to get the current time in Python
- Python – Converting string into datetime
- Sqlite – Improve INSERT-per-second performance of SQLite
- Python – Does Python have a string ‘contains’ substring method
- Python – How to lowercase a string in Python
- Python – How to make a timezone aware datetime object in Python
- Python – Why is reading lines from stdin much slower in C++ than Python
Best Answer
If you declare your column with a type of timestamp, you're in clover:
See? both int (for a column declared integer) and datetime (for a column declared timestamp) survive the round-trip with the type intact.