Python SQL日期差异查询

2024-09-30 02:27:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一个程序来找出今天的日期和出生日期之间的区别。我试着用日期差来计算他们的年龄 一直返回此消息 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)

Tags: from程序todaydatetimedateconnowprint
1条回答
网友
1楼 · 发布于 2024-09-30 02:27:16

SQL中的语法错误。在

错误信息非常明确。解析器在需要其他内容时遇到了(,而查询中只有一个(。在

一个select语句是select column, column, ...,因此您需要在pupils.dateofBirth后面加一个逗号。在

相关问题 更多 >

    热门问题