2017-07-31 185 views
0

我正在編寫一個程序,以找出今天的日期和出生日期之間的差異。我試圖用日期DIFF得到他們的年齡,但 保持返回此消息 sqlite3.OperationalError方法:近「(」:語法錯誤Python的SQL日期差異查詢

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) 

回答

0

語法錯誤在您的SQL

錯誤。消息是很明確的。分析器遇到(當它被期望別的東西,而且只有一個(在您的查詢。

一個select語句select column, column, ...所以你需要pupils.dateofBirth後一個逗號。

+0

非常感謝它的工作 –