我想要上周的所有数据。我用了
SELECT id FROM tbl
WHERE date >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND date < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
但是当我的一周从“星期一”开始时它不起作用。
我应该怎么办?
SELECT id FROM tbl WHERE date >= CURDATE() - INTERVAL (WEEKDAY(CURDATE())+7) DAY AND date < CURDATE() - INTERVAL (WEEKDAY(CURDATE())) DAY
我试试这个,它对我有用。
然后像这样改变
$lastweek = unix_to_human(time("Y-m-d H:i:s") - (7 * 24 * 60 * 60), TRUE, 'us');
SELECT id FROM tbl
WHERE date >= curdate() - $lastweek
AND date < curdate() - $lastweek
尝试
SELECT id FROM tbl
WHERE YEARweek(date) = YEARweek(curdate())