为什么不在上周提取数据

时间:2011-08-04 09:16:37

标签: mysql

为什么这不能用于从上周提取数据?

if($_GET['reminder'] == 'lastweek') {
$lastweek = date('Y-m-d', strtotime('last sunday'));
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND contacttodo.reminder BETWEEN '$lastweek' AND '$lastweek' - INTERVAL 6 DAY ORDER BY contacttodo.reminder ASC"; 

1 个答案:

答案 0 :(得分:0)

这是BETWEEN的定义:

expr BETWEEN min AND max

所以你应该把较小的值(最小值)放在第一位:

BETWEEN '$lastweek' - INTERVAL 6 DAY AND '$lastweek'

'$lastweek' - INTERVAL 6 DAY ORDER小于'$lastweek'