function find_createtime($day){
$y = date("Y", time());
$m = date("m", time());
$d = date("d", time());
if($day==1){
//今天
$time = date('Y-m-d',mktime(0, 0, 0, $m, $d, $y));
$data[] = ['time','>=',$time];
}elseif ($day==2){
//昨天
$beginYesterday=date('Y-m-d H:i:s',date(mktime(0,0,0,date('m'),date('d')-1,date('Y'))));
$endYesterday=date('Y-m-d H:i:s',date(mktime(0,0,0,date('m'),date('d'),date('Y'))-1));
$data[] = ['time','between',[$beginYesterday,$endYesterday]];
}elseif($day==3){
//导出本周
$time = date('Y-m-d',strtotime("-7 days"));
$data[] = ['time','>=',$time];
}elseif($day==4){
//导出上周
$beginLastweek=date('Y-m-d H:i:s',mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')));
$endLastweek=date('Y-m-d H:i:s',mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')));
$data[] = ['time','between',[$beginLastweek,$endLastweek]];
}elseif($day==5){
//导出本月
$time = date('Y-m-d H:i:s',mktime(0, 0, 0, $m, 1, $y));
$data[] = ['time','>=',$time];
}
return $data;
}
php获取今日时间范围和昨日时间范围本月时间范围
使用方法:
find_createtime($day)
$day =1//PHP获取当日时间范围函数
$day =2//PHP获取昨天时间范围函数
$day =3//PHP获取本周时间范围函数
$day =4//PHP获取上周时间范围函数
$day =5//PHP获取当月本月时间范围函数