php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法

//php获取今日开始时间戳和结束时间戳

$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));

$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;

//php获取昨日起始时间戳和结束时间戳

$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));

$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;

//php获取上周起始时间戳和结束时间戳

$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));

$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));

//php获取本月起始时间戳和结束时间戳

$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));

$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));


//获取今天00:00

$todaystart = strtotime(date('Y-m-d'.'00:00:00',time()));

//获取今天24:00

$todayend = strtotime(date('Y-m-d'.'00:00:00',time()+3600*24));

//统计今天注册的用户

$todayuser['create_time'] = array(between,"$todaystart,$todayend");

$todaysum = $Users->where($todayuser)->count();

//获取昨天00:00

$timestart = strtotime(date('Y-m-d'.'00:00:00',time()-3600*24));

//获取今天00:00

$timeend = strtotime(date('Y-m-d'.'00:00:00',time()));

//统计昨天注册的用户

$map['create_time'] = array(between,"$timestart,$timeend");

$daycount = $Users->where($map)->count();

$this->assign("todaysum",$todaysum);

$this->assign("daycount",$daycount);

你可能感兴趣的:(php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法)