Home  >  Article  >  Backend Development  >  PHP gets time period code

PHP gets time period code

WBOY
WBOYOriginal
2016-07-25 08:46:171042browse
  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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn