做数据统计的时候需要查询今日,昨日,本周,本月,本季度,本年的数据,便整理了一个函数,传入相应的查询类型,便能获得今日、昨日等的时间段,返回一个开始的时间戳,和结束的时间戳,上代码:
function get_time_int($name){
switch($name){
case 'yesterday':$time1=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$time2=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;break;
case 'today':$time1=mktime(0,0,0,date('m'),date('d'),date('Y'));
$time2=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;break;
case 'week':$time1=mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
$time2=mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"));break;
case 'month':$time1=mktime(0, 0 , 0,date("m"),1,date("Y"));
$time2=mktime(23,59,59,date("m"),date("t"),date("Y"));break;
case 'quarter':$season = ceil((date('n'))/3);$time1=mktime(0, 0, 0,$season*3-3+1,1,date('Y'));
$time2=mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'));break;
case 'year':$time1=strtotime(date("Y").'-1-1');
$time2=mktime(23,59,59,12,31,date("Y"));break;
default:$time1=0;$time2=time();break;
}
return [$time1,$time2];
}
返回的是起止时间戳
海报
0 条评论
117
相关文章
本站已关闭游客评论,请登录或者注册后再评论吧~