PHP time and date processing collation

Source: Internet
Author: User
Tags time and date
  1. Returns the timestamp of all months in a time period
  2. function Monthlist ($start, $end) {
  3. if (!is_numeric ($start) | |! Is_numeric ($end) | | ($end <= $start)) Return ';
  4. $start =date (' y-m ', $start);
  5. $end =date (' y-m ', $end);
  6. Convert to time stamp
  7. $start =strtotime ($start. '-01 ');
  8. $end =strtotime ($end. '-01 ');
  9. $i = 0;
  10. $d =array ();
  11. while ($start <= $end) {
  12. This adds up the total number of seconds per month calculation formula: Timestamp seconds from January 1 minus the timestamp of the current month
  13. $d [$i]=trim (Date (' Y-m ', $start), ');
  14. $start +=strtotime (' +1 month ', $start)-$start;
  15. $i + +;
  16. }
  17. return $d;
  18. }
  19. Returns the start and end dates of the week within a time period date type
  20. function Monthlist ($start, $end) {
  21. if (!is_numeric ($start) | |! Is_numeric ($end) | | ($end <= $start)) Return ';
  22. $start =date (' y-m ', $start);
  23. $end =date (' y-m ', $end);
  24. Convert to time stamp
  25. $start =strtotime ($start. '-01 ');
  26. $end =strtotime ($end. '-01 ');
  27. $i = 0;
  28. $d =array ();
  29. while ($start <= $end) {
  30. This adds up the total number of seconds per month calculation formula: Timestamp seconds from January 1 minus the timestamp of the current month
  31. $d [$i]=trim (Date (' Y-m ', $start), ');
  32. $start +=strtotime (' +1 month ', $start)-$start;
  33. $i + +;
  34. }
  35. return $d;
  36. }
  37. Returns the first and last day of a month
  38. function Getthemonth ($date)
  39. {
  40. $firstday = Date (' y-m-01 ', Strtotime ($date));
  41. $lastday = Date (' y-m-d ', Strtotime ("$firstday +1 month-1 Day");
  42. Return Array ($firstday, $lastday);
  43. }
  44. $today = Date ("y-m-d");
  45. $day =getthemonth ($today);
Copy Code
Php
  • 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.