{"id":3883,"date":"2019-06-28T21:23:58","date_gmt":"2019-06-28T15:53:58","guid":{"rendered":"https:\/\/pynative.com\/?p=3883"},"modified":"2021-03-09T10:57:35","modified_gmt":"2021-03-09T05:27:35","slug":"python-sqlite-date-and-datetime","status":"publish","type":"post","link":"https:\/\/pynative.com\/python-sqlite-date-and-datetime\/","title":{"rendered":"Python SQLite working with Date and DateTime"},"content":{"rendered":"\n
This lesson demonstrates how to work with SQLite date and timestamp types in Python and vice-versa. Most of the time, we need to insert Python Also Read<\/strong>:<\/p>\n\n\n\n Before executing the following program, please make sure you have an SQLite table with a timestamp as a column from which you want to retrieve\/insert data.<\/p>\n\n\n\n For this lesson, I am using the ‘new_developers’ table present in my SQLite database.<\/p>\n\n\n\n If a table is not present in your SQLite database, then please refer to the following articles: –<\/p>\n\n\n\n In a usual scenario, when you execute the insert query with the DateTime object, the Python sqlite3 module converts it into a string format instead of an actual DateTime. And when you run a SELECT query from Python to read DateTime values from SQLite table, the sqlite3 module will convert it into a string object. Let’s understand this scenario with a simple example.<\/p>\n\n\ndate<\/code> or
DateTime<\/code> value into an SQLite table. Also, we need to read the SQLite date and timestamp values stored in the SQLite3 database and convert them into Python
date<\/code> and
DateTime<\/code> types.<\/p>\n\n\n\n
Table of contents<\/h2>
Prerequisites<\/h2>\n\n\n\n
Python example to insert\/Retrieve DateTime from SQLite table<\/h2>\n\n\n\n