查找最近七天的记录

时间:2014-04-16 05:26:07

标签: php mysql

$today = date('Y-m-d');
$countreview= mysql_query("SELECT count(review),
                                  time
                        FROM review
                        WHERE time BETWEEN ($today - INTERVAL 7 DAY) AND $today
                        GROUP BY time");

5 个答案:

答案 0 :(得分:1)

试试这个:

SELECT * from users where created_time > (NOW()-INTERVAL 7 DAY)

答案 1 :(得分:1)

 time BETWEEN DATE_SUB(DATE( '$today'),INTERVAL 7 DAY) AND '$today'

如果您想与当前时间进行比较now()

time BETWEEN DATE_SUB(DATE( NOW()),INTERVAL 7 DAY) AND NOW()

答案 2 :(得分:1)

试试这个

$sql="SELECT  * FROM  review  WHERE DATE(time) = DATE_SUB( CURDATE( ) , INTERVAL 7)";

我希望这就是你要找的东西

快乐编码!!

答案 3 :(得分:1)

您可以在MySQL WHERE子句中使用它来返回在过去7天/周内创建的记录:

created >= DATE_SUB(CURDATE(),INTERVAL 7 day)

在减法中也使用NOW()来给出hh:mm:ss分辨率。因此,要返回在过去24小时内准确创建(到第二个)的记录,您可以这样做:

created >= DATE_SUB(NOW(),INTERVAL 1 day)

答案 4 :(得分:1)

我认为你会发现它最简单:

$sevenDayOld = date('Y-m-d', strtotime('-7 days 00:00:00'));
$SQL = "SELECT count(review),time, FROM review
                    WHERE time > '" . $sevenDayOld ."'
                    GROUP BY time";