Python 在sqlite中将日期时间存储为整数
当我将日期时间字符串值存储在sqlite表中时,我试图将其转换为整数。我正在使用Python(Flask)。我在以下查询中收到“插入操作出错” 有什么想法吗Python 在sqlite中将日期时间存储为整数,python,sqlite,flask,Python,Sqlite,Flask,当我将日期时间字符串值存储在sqlite表中时,我试图将其转换为整数。我正在使用Python(Flask)。我在以下查询中收到“插入操作出错” 有什么想法吗 with sql.connect("flaskjournal.db") as con: cur = con.cursor() t_i = strftime('%s','time_in') cur.execute("INSERT INTO entries (beach, board, swell, wind, score, notes, ti
with sql.connect("flaskjournal.db") as con:
cur = con.cursor()
t_i = strftime('%s','time_in')
cur.execute("INSERT INTO entries (beach, board, swell, wind, score, notes, time_in)
VALUES (?,?,?,?,?,?,?)",(beach, board, swell, wind, score, notes, t_i))
con.commit()
msg = "Record successfully added"
您可以改为使用时间戳
import time
from datetime import datetime
timestamp = int(time.mktime(datetime_object.timetuple())
使
t_i
通过创建表模式插入unix时间戳。因此,您不需要从python中处理它
sqlite> create table t1 (
...> id integer primary key,
...> time t_i default (strftime('%s', 'now')),
...> txt text);
您是否尝试在插入之前打印所有变量?它们看起来都是正确的吗?谢谢你的帮助,通过在这句话上面的python代码中进行转换,以不同的方式解决了这个问题。谢谢你的帮助…使用了不同的方法,但成功了。谢谢…这让我想到在sqlite内容上面用python代码进行转换。很高兴我能提供帮助