php中获取今日开始上周起始上月时间戳范围写法

2020-04-15      11素材网      879     

这是php获取当月月初和月末的时间戳

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

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


//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'));


PHP mktime() 函数用于返回一个日期的 Unix 时间戳。

 

语法: 

mktime(hour,minute,second,month,day,year,is_dst)

 

参数  描述

hour  可选。规定小时。

minute  可选。规定分钟。

second  可选。规定秒。

month  可选。规定用数字表示的月。

day  可选。规定天。

year  可选。规定年。在某些系统上,合法值介于 1901 - 2038 之间。不过在 PHP 5 中已经不存在这个限制了。

is_dst

可选。如果时间在日光节约时间(DST)期间,则设置为1,否则设置为0,若未知,则设置为-1。


$map['time']  = array('BETWEEN',array($beginThismonth,$endThismonth));

$mrecharge = $User_recharge->where($map)->sum('recharge_num');


TAG