gpt4 book ai didi

php - 我的值(value)为 2018-05-03 11 :02:00 in mysql i want to pass this in my where condition using php

转载 作者:行者123 更新时间:2023-11-29 07:33:12 25 4
gpt4 key购买 nike

在我的表中,“时间”数据出现在这个日期时间的 2018-05-03 11:02:00。所以我想通过传递这个日期时间来获取数据。

这是我的代码:

$query1=$this->db->query("SELECT sum(count) As total, sum(status) As 
is_completed FROM `tasks` WHERE `staff_id` = '$datas[$i]' AND `time` >
DATE_SUB(CURDATE(), INTERVAL 1 HOUR)");

此代码未显示任何结果,但在此日期时间存在数据。如何我可以将这个日期时间作为 where 条件传递吗

最佳答案

CURDATE() 只返回一个日期。因此,当您执行 DATE_SUB(CURDATE(), INTERVAL 1 HOUR) 时,您将返回相当于 23:00:00 Yesterday

看起来对于你正在尝试做的事情,使用 NOW() 会更好。

您可以尝试以下查询:

SELECT sum(count) AS total, sum(status) AS is_completed
FROM `tasks` WHERE `staff_id` = '$datas[$i]'
AND `time` > DATE_SUB(NOW(), INTERVAL 1 HOUR)

关于php - 我的值(value)为 2018-05-03 11 :02:00 in mysql i want to pass this in my where condition using php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50148377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com