數(shù)據(jù)庫(kù)字段是createtime 里面保存的是時(shí)間戳
//數(shù)據(jù)庫(kù)字段是createtime 里面保存的是時(shí)間戳
//本周第一天0點(diǎn)的Unix時(shí)間戳
$week = strtotime("last Sunday");//把周日當(dāng)做是一個(gè)禮拜的開始,如果想把周一當(dāng)做是一個(gè)禮拜的開始,就把Sunday換成Mondy
echo date('Y-m-d H:i:s',$week)."\n";
//本月第一天0點(diǎn)的Unix時(shí)間錯(cuò)
$month = strtotime(date('Y-m-1'));
echo date('Y-m-d H:i:s',$month)."\n";
//////////////////////
//取得當(dāng)天0點(diǎn)的Unix時(shí)間戳
$day = strtotime(date('Ymd'));
echo date('Y-m-d H:i:s',$day);
//取得昨天0點(diǎn)的Unix時(shí)間戳
$yesterday = strtotime(date('Ymd',strtotime('-1 day')));
echo date('Y-m-d H:i:s',$yesterday);
//取得上周0點(diǎn)的Unix時(shí)間戳
$week = strtotime(date('Ymd',strtotime('-1 week')));
echo date('Y-m-d H:i:s',$week);
//取得上月0點(diǎn)的Unix時(shí)間戳
$month = strtotime(date('Ymd',strtotime('-1 month')));
echo date('Y-m-d H:i:s',$month);
///////////////////////////
//取得上周的第一天的Unix時(shí)間戳
$week = strtotime("-2 Sunday");
//如果是前2周,把-2改成-3,前3周,改成-4,以此類推……
echo date('Y-m-d H:i:s',$week)."<br>";
//取得上個(gè)月第一天的Unix時(shí)間戳
$month = strtotime(date('Y-m-1',strtotime('-1 Month')));
//上2個(gè)月把 -1 改成 -2 ,上3個(gè)月 改成-3,以此類推……
echo date('Y-m-d H:i:s',$month)."<br>";
///////////////////////////
//取得當(dāng)天0點(diǎn)的Unix時(shí)間戳
$day = strtotime(date('Ymd'));
echo date('Y-m-d H:i:s',$day);
//取得昨天0點(diǎn)的Unix時(shí)間戳
$yesterday = strtotime(date('Ymd',strtotime('-1 day')));
echo date('Y-m-d H:i:s',$yesterday);
//取得上周0點(diǎn)的Unix時(shí)間戳
$week = strtotime(date('Ymd',strtotime('-1 week')));
echo date('Y-m-d H:i:s',$week);
//取得上月0點(diǎn)的Unix時(shí)間戳
$month = strtotime(date('Ymd',strtotime('-1 month')));
echo date('Y-m-d H:i:s',$month);
demo:
<?php
/*
*按今天,本周,本月,本季度,本年,全部查詢預(yù)約單數(shù)據(jù)
* $day 代表查詢條件 $cid 代表 公司id
*返回array $data 查詢條件 數(shù)組
*/
class ReserveModel extends BaseModel {
public function find_createtime($day,$cid){
//查詢當(dāng)天數(shù)據(jù)
if($day==1){
$today=strtotime(date(‘Y-m-d 00:00:00‘));
$data[‘cid‘]=$cid;
$data[‘createtime‘] = array(‘egt‘,$today);
return $data;
//查詢本周數(shù)據(jù)
}else if($day==2){
$arr=array();
$arr=getdate();
$num=$arr[‘wday‘];
$start=time()-($num-1)*24*60*60;
$end=time()+(7-$num)*24*60*60;
$data[‘cid‘]=$cid;
$data[‘createtime‘] = array(‘between‘,array($start,$end));
return $data;
//查詢本月數(shù)據(jù)
}else if($day==3){
$start=strtotime(date(‘Y-m-01 00:00:00‘));
$end = strtotime(date(‘Y-m-d H:i:s‘));
$data[‘cid‘]=$cid;
$data[‘createtime‘] = array(‘between‘,array($start,$end));
return $data;
//查詢本季度數(shù)據(jù)
}else if($day==4){
$month=date(‘m‘);
if($month==1 || $month==2 ||$month==3){
$start=strtotime(date(‘Y-01-01 00:00:00‘));
$end=strtotime(date("Y-03-31 23:59:59"));
}elseif($month==4 || $month==5 ||$month==6){
$start=strtotime(date(‘Y-04-01 00:00:00‘));
$end=strtotime(date("Y-06-30 23:59:59"));
}elseif($month==7 || $month==8 ||$month==9){
$start=strtotime(date(‘Y-07-01 00:00:00‘));
$end=strtotime(date("Y-09-30 23:59:59"));
}else{
$start=strtotime(date(‘Y-10-01 00:00:00‘));
$end=strtotime(date("Y-12-31 23:59:59"));
}
$data[‘cid‘]=$cid;
$data[‘createtime‘] = array(‘between‘,array($start,$end));
return $data;
//查詢本年度數(shù)據(jù)
}else if($day==5){
$year=strtotime(date(‘Y-01-01 00:00:00‘));
$data[‘cid‘]=$cid;
$data[‘createtime‘] = array(‘egt‘,$year);
return $data;
//全部數(shù)據(jù)
}else{
$data[‘cid‘]=$cid;
return $data;
}
}
}
?>
然后再CompanyAction.class.php中寫
$list=$Shop->where($data)->select();
$this->list=$list;
*$this->display();*
數(shù)據(jù)就查找出來(lái)了。。。