[英]Python SQL date diff query
我正在編寫一個程序,以找出今天的日期和出生日期之間的差異。 我正在嘗試使用Date Diff來獲取其年齡,但是該方法不斷返回此消息sqlite3.OperationalError:在“(”附近:語法錯誤
def workoutage():
print ("Current date and time: " , datetime.datetime.now())
print ("Or like this: " ,datetime.datetime.now().strftime("%Y-%m-%d"))
today = datetime.datetime.now().strftime("%Y-%m-%d")
print("the date today is ", today)
con = lite.connect(db)
cur = con.cursor()
' - DateofBirth ) from Pupils"
ageQuery = "SELECT pupils.dateofBirth DATEDIFF(day, '"+today+",
pupils.dateofBirth) AS NumberOfDays from Pupils"""
cur.execute(ageQuery)
ageQueryList = cur.fetchall()
showList(ageQueryList)
SQL中的語法錯誤。
該錯誤消息非常明顯。 解析器遇到了(
當它期望其他東西時,在查詢中只有一個(
。
select
語句是select column, column, ...
因此您需要在pupils.dateofBirth
之后pupils.dateofBirth
逗號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.