NotCamelCase
NotCamelCase

Reputation: 1083

Storing python dates in sqlite3

is not there any way to store python dates or pyqt4 dates (QDate) in sqlite3 ? I'd not like to use sqlite's date types since i'll need to find the difference between dates that i'll store.That's what i'm trying :

    record = QtCore.QDate.currentDate()
    latest = self.calendar.selectedDate()

    db = sql.connect(":memory:")
    cur = self.db.cursor()
    cur.execute("CREATE TABLE  invoices(record, latest)")
    cur.execute("INSERT INTO invoices VALUES (?, ?)", (record, latest)) 
    db.commit()

That's the error : sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type. Thanks in advance.

Upvotes: 1

Views: 941

Answers (2)

Ahmed ElMatbouly
Ahmed ElMatbouly

Reputation: 1

I tried many methods and most straightforward is convert it to timestamp, then when retrieve it back convert from timestamp to date and that's best solution because if you store it like string object it will be impossible to do logic operations on your data but with timestamp its simple...

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799440

No. Convert it to a timestamp first.

Upvotes: 3

Related Questions