日期:2014-05-17  浏览次数:20675 次

取数据
从数据库中取上周的数据,也就是本周取上一周的,下周取本周的,怎么取啊

------解决方案--------------------
指定日期范围就是了
------解决方案--------------------
<?php
function getLastWeekDate($date){
$iDate = strtotime($date);
$iLastDate = $iDate-7*24*60*60;
if(date('w',$iLastDate) == 0){ //周日
$sLastWeekStart = date('Y-m-d 00:00:00',$iLastDate-7*24*60*60);
$sLastWeekEnd = date('Y-m-d 23:59:59',$iLastDate);
}else{ //非周日
$sLastWeekStart = date('Y-m-d 00:00:00',$iLastDate-date('w',$iLastDate)*24*60*60);
$sLastWeekEnd = date('Y-m-d 23:59:59',$iLastDate+(7-date('w',$iLastDate))*24*60*60);
}
return array('start_time'=>$sLastWeekStart,'end_time'=>$sLastWeekEnd);
}

$arrDate = getLastWeekDate('2011-07-11 12:00:00');
var_dump($arrDate);
?>