如何在CURDATE + 7天INTERVAL中提取一周的约会价值

时间:2015-01-20 15:14:56

标签: php mysql

我准备了一个小拉请求,从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();

2 个答案:

答案 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