PHP 获取今天,昨天,前天,过去7天,过去30天,本周,上周的开始和结束时间
- PHP
- 2022-02-12
- 4392
- 0
protected function selectTime($key)
{
switch ($key) {
//今天
case 1:
$time[0] = mktime(0,0,0,date('m'),date('d'),date('Y'));
$time[1] = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
break;
//昨天
case 2:
$time[0] = mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$time[1] = mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
break;
//前天
case 3:
$time[0] = mktime(0,0,0,date('m'),date('d')-2,date('Y'));
$time[1] = mktime(0,0,0,date('m'),date('d')-1,date('Y'))-1;
break;
//过去7天
case 4:
$time[0] = mktime(0,0,0,date('m'),date('d')-7,date('Y'));
$time[1] = mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
break;
//过去30天
case 5:
$time[0] = mktime(0,0,0,date('m'),date('d')-30,date('Y'));
$time[1] = mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
break;
//本周
case 6:
$time[0] = mktime(0, 0, 0, date('m'), (date('d') - (date('w')>0 ? date('w') : 7) + 1), date('Y'));
$time[1] = mktime(0, 0, 0, date('m'), (date('d') - (date('w')>0 ? date('w') : 7) + 7), date('Y'));
break;
//上周
case 7:
$time[0] = mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
$time[1] = mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
break;
//本月
case 8:
$time[0] = mktime(0,0,0,date('m'),1,date('Y'));
$time[1] = mktime(23,59,59,date('m'),date('t'),date('Y'));
break;
//上月
case 9:
$time[0] = mktime(0, 0 , 0,date("m")-1,1,date("Y"));
$time[1] = mktime(23,59,59,date("m") ,0,date("Y"));
break;
}
return $time;
}