以下得出的数据都是时间戳,请大家自己转换
今天
$startTime = mktime(0,0,0,date("m"),date("d"),date("Y")); $endTime = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
昨天
$startTime = mktime(0,0,0,date("m"),date("d")-1,date("Y")); $endTime = mktime(0,0,0,date("m"),date("d"),date("Y"))-1;
明天
$startTime = mktime(0,0,0,date("m"),date("d")+1,date("Y")); $endTime = mktime(0,0,0,date("m"),date("d")+2,date("Y"))-1;
本周
$startTime=mktime(0,0,0,date('m'),date('d')-date('w')+1,date('Y')); $endTime=mktime(23,59,59,date('m'),date('d')-date('w')+7,date('Y'));
上周
$startTime=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')); $endTime=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
下周
$startTime=mktime(0,0,0,date('m'),date('d')-date('w')+1+7,date('Y')); $endTime=mktime(23,59,59,date('m'),date('d')-date('w')+7+7,date('Y'));
本月
$startTime = mktime(0,0,0,date("m"),1,date("Y")); $endTime = mktime(23,59,59,date('m'),date('t'),date('Y'));
上月
$startTime = mktime(0,0,0,date("m")-1,1,date("Y")); $endTime = mktime(0,0,0,date("m"),1,date("Y"))-1;
本季度
$getMonthDays = date("t",mktime(0, 0 , 0,date('n')+(date('n')-1)%3,1,date("Y"))); //本季度未最后一月天数 echo '<br>本季度:<br>'; echo date('Y-m-d H:i:s', mktime(0, 0, 0,date('n')-(date('n')-1)%3,1,date('Y'))),"\n"; echo date('Y-m-d H:i:s', mktime(23,59,59,date('n')+(date('n')-1)%3,$getMonthDays,date('Y'))),"\n";
$season = ceil((date('n'))/3); //当月是第几季度echo '<br>本季度起始时间:<br>'; echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n"; echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n"; $season = ceil((date('n'))/3)-1;//上季度是第几季度echo '<br>上季度起始时间:<br>'; echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n"; echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n";
今年
$startTime = mktime(00,00,00,01,01,date('Y')); $endTime = mktime(23,59,59,12,31,date('Y'));
明年
$startTime = mktime(00,00,00,01,01,date('Y')+1); $endTime = mktime(23,59,59,12,31,date('Y')+1);
去年
$startTime = mktime(00,00,00,01,01,date('Y')-1); $endTime = mktime(23,59,59,12,31,date('Y')-1);