Home > Backend Development > PHP Tutorial > 取数据,该如何解决

取数据,该如何解决

WBOY
Release: 2016-06-13 10:18:42
Original
863 people have browsed it

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

------解决方案--------------------
指定日期范围就是了
------解决方案--------------------
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);
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template