转换为srtftime

2024-10-16 22:27:58 发布

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

SELECT_NO_PROCESSED_QRCODES = "SELECT id, visit_date, added_in_monitoring FROM locations_qrcode " \
      "WHERE DATE_FORMAT(visit_date, '%Y%m%d') = %(value)s"

此SQL在python(def)函数之外工作得非常好。 这是因为MySQL的DATE_FORMAT因为在Python函数中而停止工作吗

我的访问日期字段是一个日期时间字段,我需要在SQL中使用strftime来转换为(“%Y-%m-%d”),我如何才能做到这一点

比如:strftime(visit_date,'% Y-% m-% d')


Tags: 函数noinidformataddedsqldate
1条回答
网友
1楼 · 发布于 2024-10-16 22:27:58

1370(42000):对于例程“visit_date.srftime”,对用户“erico”@“%”拒绝执行命令

用户-密码和数据库正常

def process_qrcodes():
    now = datetime.now().strftime('%Y-%m-%d')
    while True:

        try:
            cur = conn.cursor()
            #QRCODES = "SELECT id, added_in_monitoring, string FROM locations_qrcode WHERE added_in_monitoring='0'"

            now = datetime.now().strftime("%Y-%m-%d")
            NON_PROCESSED_QRCODES = "SELECT id, added_in_monitoring, string FROM locations_qrcode " \
                                    "WHERE visit_date.srftime('%%Y-%%m-%%d') =%s" % (now,)

            cur.execute(NON_PROCESSED_QRCODES)
            results = cur.fetchall()
            for result in results:
                idqrcode = result[0]
                string = result[2]
                process_status_qrcode(idqrcode, string)
                print("OI")

        except Exception as e:
            print(e)

        time.sleep(10)

相关问题 更多 >