【发布时间】:2019-07-13 08:25:00
【问题描述】:
我想使用 Python 将日期时间插入 sqlite。
我尝试使用 Python 的 datetime 和 strftime,但没有成功。
Test 的时间字段的类型为 Numeric (Datetime)。
from datetime import datetime as dt
rows = db.execute(
'INSERT INTO test (time) VALUES (:time)',
time=dt.now().strftime('%Y-%m-%d %H:%M:%S'))
RuntimeError: (sqlite3.OperationalError) near "'2019-05-19 17:14:25'": 语法错误 [SQL: INSERT INTO test (time) VALUES ('2019-05-19 17:14:25')]
【问题讨论】:
-
复制查询并直接在数据库中运行,也许它可以为您提供有关问题的更多信息。数字可能意味着像时间戳这样的数字
标签: python python-3.x sqlite datetime