【问题标题】:Update date column to current date将日期列更新为当前日期
【发布时间】:2019-09-16 15:39:49
【问题描述】:

我已经使用工作台创建了一个日期列,现在我必须使用 sql 查询或使用 python 代码将该列的所有值更新为当前日期

mydb = mysql.connector.connect(host="localhost", user="root", 
password="afif123", db="library")
mycursor = mydb.cursor()
fill = '''UPDATE issued_book SET Today = current_date()'''
mycursor.execute(fill)
#or
today = datetime.datetime.now()
fill = '''UPDATE issued_book SET Today = %s'''
mycursor.execute(fill, [today])

以上两种尝试都无济于事

我将日期列的数据类型保留为 DATETIME()

【问题讨论】:

    标签: python-3.x mysql-workbench


    【解决方案1】:

    do it in mysql,只需稍微修改您的第一个查询...

    update issued_book set today = now()
    

    而不是current_date(),它不是mysql函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多