PHP获取时间段代码
时间:2021-07-01 10:21:17
帮助过:22人阅读
- $start_time = '';
- $end_time = '';
-
- switch ($type) {
- case 'thisWeek'://本周
- $start_time = date("Y-m-d H:i:s",strtotime("-0 week Monday"));
- $end_time = date("Y-m-d H:i:s",strtotime("-0 week Sunday"));
- break;
- case 'lastWeek'://上周
- $start_time = date("Y-m-d H:i:s",strtotime("-1 week Monday"));
- $end_time = date("Y-m-d H:i:s",strtotime("-1 week Sunday"));
- break;
- case 'thisMonth'://本月
- $start_time = date("Y-m-d H:i:s",strtotime("first day of this month"));
- $end_time = date('Y-m-d H:i:s',strtotime("last day of this month"));
- break;
- case 'lastMonth'://上个月
- $start_time = date("Y-m-d H:i:s",strtotime("first day of last month"));
- $end_time = date('Y-m-d H:i:s',strtotime("last day of last month"));
- break;
- case 'lastMonth2'://上上个月
- $start_time = date("Y-m-d H:i:s",strtotime("first day of last month -1 month"));
- $end_time = date('Y-m-d H:i:s',strtotime("last day of last month -1 month"));
- break;
- case 'lastMonth3'://上上上个月
- $start_time = date("Y-m-d H:i:s",strtotime("first day of last month -2 month"));
- $end_time = date('Y-m-d H:i:s',strtotime("last day of last month -2 month"));
- break;
- default :
- $start_time = date("Y-m-d H:i:s");
- $end_time = date("Y-m-d H:i:s");
- }
|
PHP