Home >Backend Development >PHP Tutorial >PHP gets the code of last week, this week, last month, this month, this quarter, and last quarter

PHP gets the code of last week, this week, last month, this month, this quarter, and last quarter

WBOY
WBOYOriginal
2016-07-25 08:44:171111browse
  1. echo date("Ymd",strtotime("now")), "\n";
  2. echo date("Ymd",strtotime("-1 week Monday")), " \n";
  3. echo date("Ymd",strtotime("-1 week Sunday")), "\n";
  4. echo date("Ymd",strtotime("+0 week Monday")), "\n" ";
  5. echo date("Ymd",strtotime("+0 week Sunday")), "\n";
  6. echo "**********The month:";
  7. echo date( 'n');
  8. echo "************Day of the week:";
  9. echo date("w");
  10. echo "************Day of the month:" ;
  11. echo date("t");
  12. echo "*******";
  13. echo '
    Last week's start time:
    ';
  14. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y")))," \n";
  15. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7, date("Y"))),"\n";
  16. echo '
    Start time of this week:
    ';
  17. echo date("Y-m-d H:i:s",mktime(0, 0, 0,date("m"),date("d")-date("w")+1,date("Y"))),"\n";
  18. echo date("Y-m-d H:i :s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"\n";
  19. echo '
    Start time of last month:
    ';
  20. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1 ,date("Y"))),"\n";
  21. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y" ))),"\n";
  22. echo '
    Start time of this month:
    ';
  23. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date ("m"),1,date("Y"))),"\n";
  24. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"), date("t"),date("Y"))),"\n";
  25. $season = ceil((date('n'))/3);//What quarter is this month
  26. echo '
    Start time of this quarter:
    ';
  27. echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date( 'Y'))),"\n";
  28. 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";
  29. $season = ceil((date('n'))/3) -1; //Which quarter is the last quarter? echo '
    Start time of last quarter:
    ';
  30. echo date('Y-m-d H:i:s', mktime(0, 0, 0 ,$season*3-3+1,1,date('Y'))),"\n";
  31. 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";
  32. ?>
Copy code

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