Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试检索从现在起一小时内有预定时间的记录,以便通知即将到来的约会。
以下代码是我尝试过的,但没有返回任何记录。
$stmt = $conn->prepare("SELECT $columns FROM $table WHERE scheduled BETWEEN NOW() AND DATE_SUB(NOW(), INTERVAL 1 HOUR) ORDER BY id DESC");
你的答案本身就有问题。
DATE_ADD
应使用而不是 DATE_SUB。由于您正在寻找未来的数据,因此 date_add 应该为您提供未来的值。
希望这可以帮助。
$stmt = $conn->prepare("SELECT $columns FROM $table WHERE scheduled < DATE_ADD(NOW(), INTERVAL +1 HOUR) ORDER BY id DESC");
我认为这样可以值得