2017-08-02 135 views
0

我上增加了變量到SQLite數據庫如何通過蟒蛇

curs.execute("INSERT INTO EntryLog(EntryTime)VALUES(?)",(time) 

,使這項工作我怎麼能做出把當前日期時間值轉換成時間樹莓項目的工作添加日期時間到SQL? (EntryTime是SQL DATETIME值,我需要的日期和時間在同一列)

回答

0

你需要一個像time.strftime('%Y-%m-%d')

from datetime import datetime 

time=datetime.now() 
curs.execute("INSERT INTO EntryLog(EntryTime)VALUES(?)",(time.strftime('%Y-%m-%d')) 
+0

格式化時間格式年月日的字符串,我得到的是沒有屬性說,現在 –

+0

錯誤@Mert Yalcin你需要導入模塊的日期時間。如果你使用'from datetime import datetime',你可以像在答案中那樣做。如果你只是使用'import datetime',你將需要'time = datetime.datetime.now()' – nacho

+0

感謝它現在的作品 –