在sqlite3中存储python日期

hl0ma9xz  于 2023-05-18  发布在  SQLite
关注(0)|答案(2)|浏览(206)

有没有办法在sqlite3中存储python日期或pyqt 4日期(QDate)?我不喜欢使用sqlite的日期类型,因为我需要找到我存储的日期之间的差异。这就是我正在尝试的:

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()

这就是错误:sqlite3.InterfaceError:绑定参数0时出错-可能是不支持的类型。先谢谢你了。

yx2lnoni

yx2lnoni1#

不行先把它转换成时间戳

6ju8rftf

6ju8rftf2#

我尝试了许多方法,最直接的是将其转换为时间戳,然后在检索时将其从时间戳转换为日期,这是最好的解决方案,因为如果您将其存储为字符串对象,则不可能对您的数据进行逻辑操作,但使用时间戳它很简单。

相关问题