我准备了一个小拉请求,从DB中提取今日约会:
$getAppointmentsToday = $db->prepare("SELECT * FROM appointments WHERE DATE(appointment_date) = CURDATE()");
$getAppointmentsToday->execute();
我尝试修改此语句以在接下来的7天内拉出约会,但遇到了一些麻烦:
$getAppointmentsWeek = $db->prepare("SELECT * FROM appointments WHERE DATE(appointment_date) = (CURDATE(), INTERVAL 7 DAYS)");
$getAppointmentsWeek->execute();
答案 0 :(得分:0)
您现在正在检查日期CURDATE()+ 7天,而不是日期间隔。使用:
SELECT * FROM appointments WHERE DATE(appointment_date) <= (CURDATE(), INTERVAL 7 DAYS) AND DATE(appointment_date) >= CURDATE()
答案 1 :(得分:0)
您可以使用BETWEEN
运算符:
...
WHERE DATE(appointment_date)
BETWEEN CURDATE()
AND CURDATE() + INTERVAL 7 DAY