Php date instance: get last week, this week, last month, this month, this quarter, last quarter

Source: Internet
Author: User
Php date instance: get last week, this week, last month, this month, this quarter, last quarter

For example, php obtained last week, this week, last month, this month, this quarter, and the last quarter.

  1. Date_default_timezone_set ('prc ');
  2. Date ("Y-m-d H: I: s", strtotime ("+ 2 year "));
  3. Date ("Y-m-d H: I: s", strtotime ("+ 2 month "));
  4. Date ("Y-m-d H: I: s", strtotime ("+ 2 week "));
  5. Date ("Y-m-d H: I: s", strtotime ("+ 2 day "));
  6. Date ("Y-m-d H: I: s", strtotime ("+ 2 hour "));
  7. Date ("Y-m-d H: I: s", strtotime ("+ 2 minute "));
  8. Date ("Y-m-d H: I: s", strtotime ("+ 2 second "));
  9. Echo date ("Ymd", strtotime ("now"), "\ n ";
  10. Echo date ("Ymd", strtotime ("-1 week Monday"), "\ n ";
  11. Echo date ("Ymd", strtotime ("-1 week Sunday"), "\ n ";
  12. Echo date ("Ymd", strtotime ("+ 0 week Monday"), "\ n ";
  13. Echo date ("Ymd", strtotime ("+ 0 week Sunday"), "\ n ";
  14. Echo "********** months :";
  15. Echo date ('N ');
  16. Echo "********** week :";
  17. Echo date ("w ");
  18. Echo "********** number of days this month :";
  19. Echo date ("t ");
  20. Echo "*********";
  21. Echo'
    Last week:
    ';
  22. Echo date ("Y-m-d H: I: s", mktime (0, 0, 0, date ("m"), date ("d ") -date ("w") + 1-7, date ("Y"), "\ n ";
  23. Echo date ("Y-m-d H: I: s", mktime (23, 59, 59, date ("m"), date ("d ") -date ("w") + 7-7, date ("Y"), "\ n ";
  24. Echo'
    This week:
    ';
  25. Echo date ("Y-m-d H: I: s", mktime (0, 0, 0, date ("m"), date ("d ") -date ("w") + 1, date ("Y"), "\ n ";
  26. Echo date ("Y-m-d H: I: s", mktime (23, 59, 59, date ("m"), date ("d ") -date ("w") + 7, date ("Y"), "\ n ";
  27. Echo'
    Last month:
    ';
  28. Echo date ("Y-m-d H: I: s", mktime (0, 0, 0, date ("m")-1,1, date ("Y"), "\ n ";
  29. Echo date ("Y-m-d H: I: s", mktime (23, 59, 59, date ("m"), 0, date ("Y "))), "\ n ";
  30. Echo'
    This month:
    ';
  31. Echo date ("Y-m-d H: I: s", mktime (0, 0, 0, date ("m"), 1, date ("Y"), "\ n ";
  32. Echo date ("Y-m-d H: I: s", mktime (23, 59, 59, date ("m"), date ("t "), date ("Y"), "\ n ";
  33. $ Season = ceil (date ('N')/3); // The quarter of the current month
  34. Echo'
    This quarter:
    ';
  35. Echo date ('Y-m-d H: I: S', mktime (0, 0, 0, $ season * 3-3 + 1,1, date ('Y'), "\ n ";
  36. Echo date ('Y-m-d H: I: S', mktime (, 59, $ season * 3, date ('t', mktime (0, 0, 0, $ season * 3, 1, date ("Y"), date ('Y'), "\ n ";
  37. $ Season = ceil (date ('N')/3)-1; // the first quarter of the last quarter
  38. Echo'
    Last quarter:
    ';
  39. Echo date ('Y-m-d H: I: S', mktime (0, 0, 0, $ season * 3-3 + 1,1, date ('Y'), "\ n ";
  40. Echo date ('Y-m-d H: I: S', mktime (, 59, $ season * 3, date ('t', mktime (0, 0, 0, $ season * 3, 1, date ("Y"), date ('Y'), "\ n ";
  41. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.