数据库中有一个表作为P_order 现在我想要获取该数据库中最后一周的条目.... 因为我获取了当前日期的条目....但是无法获取最后一周的条目......
<?php
$wherecat = "`p_order_status` = 'active' AND `p_order_date` LIKE '".date('Y-m-d')."%' ";
$catsql =$general->GetRows('*' ,'p_order' ,$wherecat);
$catRes = mysql_num_rows($catsql);
?>
<p><?=$catRes;?></p>
<div class="box1">
<span class="li_cloud"></span>
<h3>Order Placed in Last Week</h3>
</div>
<?php
$wherecat1 = "`p_order_status` = 'active' AND `p_order_date` LIKE '".date('Y-m-d',strtotime('-1 day')). "%' ";
$catsql1 =$general->GetRows('*' ,'p_order' ,$wherecat1);
$catRes1 = mysql_num_rows($catsql1);
?>
<p><?=$catRes1;?></p>
答案 0 :(得分:0)
尝试这样的事情:
SELECT * FROM p_order WHERE p_order_date > DATE_SUB(CURDATE(), INTERVAL 1 WEEK);
或
SELECT * FROM p_order WHERE p_order_date > DATE_SUB(NOW(), INTERVAL 1 WEEK);
答案 1 :(得分:0)
试试这段代码: -
$wherecat1 = "`p_order_status` = 'active'
AND `p_order_date` >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND p_order_date < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY ";
答案 2 :(得分:0)
SELECT * FROM p_order WHERE date(p_order_date) > DATE_SUB(CURDATE(), INTERVAL 1 WEEK);
或强>
$wherecat1 = "`p_order_status` = 'active' AND date(`p_order_date`) > DATE_SUB(CURDATE(), INTERVAL 1 WEEK)";