当前位置:Gxlcms > PHP教程 > PHP获取时间段代码

PHP获取时间段代码

时间:2021-07-01 10:21:17 帮助过:22人阅读

  1. $start_time = '';
  2. $end_time = '';
  3. switch ($type) {
  4. case 'thisWeek'://本周
  5. $start_time = date("Y-m-d H:i:s",strtotime("-0 week Monday"));
  6. $end_time = date("Y-m-d H:i:s",strtotime("-0 week Sunday"));
  7. break;
  8. case 'lastWeek'://上周
  9. $start_time = date("Y-m-d H:i:s",strtotime("-1 week Monday"));
  10. $end_time = date("Y-m-d H:i:s",strtotime("-1 week Sunday"));
  11. break;
  12. case 'thisMonth'://本月
  13. $start_time = date("Y-m-d H:i:s",strtotime("first day of this month"));
  14. $end_time = date('Y-m-d H:i:s',strtotime("last day of this month"));
  15. break;
  16. case 'lastMonth'://上个月
  17. $start_time = date("Y-m-d H:i:s",strtotime("first day of last month"));
  18. $end_time = date('Y-m-d H:i:s',strtotime("last day of last month"));
  19. break;
  20. case 'lastMonth2'://上上个月
  21. $start_time = date("Y-m-d H:i:s",strtotime("first day of last month -1 month"));
  22. $end_time = date('Y-m-d H:i:s',strtotime("last day of last month -1 month"));
  23. break;
  24. case 'lastMonth3'://上上上个月
  25. $start_time = date("Y-m-d H:i:s",strtotime("first day of last month -2 month"));
  26. $end_time = date('Y-m-d H:i:s',strtotime("last day of last month -2 month"));
  27. break;
  28. default :
  29. $start_time = date("Y-m-d H:i:s");
  30. $end_time = date("Y-m-d H:i:s");
  31. }

PHP

人气教程排行