错误 – “SQLite DateTime类型仅接受Python”“日期时间和日期对象作为输入”.

前端之家收集整理的这篇文章主要介绍了错误 – “SQLite DateTime类型仅接受Python”“日期时间和日期对象作为输入”.前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图像这样声明一个包含Datetime的变量

ts1.departure_date = '2012-03-03 10:10:10'

但后来我收到了这个错误

StatementError: (exceptions.TypeError) sqlite DateTime type only accepts Python datetime and date objects as input.

我想知道用datetime格式声明变量的正确方法是什么?提前致谢

解决方法

首先导入datetime类:

from datetime import datetime

然后创建一个datetime对象并使用它来设置您的属性

ts1.departure_date = datetime(2012,3,10,10)

猜你在找的Sqlite相关文章