2017-12-18 104 views

回答

2

您可能試圖將插入日期時間爲字符串。使用datetime對象和let the database driver handle the type conversion automatically參數化:

from datetime import datetime 

date_string = "Sun, 17 Dec 2017 14:26:07 GMT" 

dt = datetime.strptime(date_string, "%a, %d %b %Y %H:%M:%S %Z") 

cursor.execute('INSERT INTO some_table (somecol) VALUES (%s)', (dt,)) 
相關問題