PHP time and date processing

Source: Internet
Author: User
PHP time and date processing

  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 timestamp
  7. $ Start = strtotime ($ start. '-01 ');
  8. $ End = strtotime ($ end. '-01 ');
  9. $ I = 0;
  10. $ D = array ();
  11. While ($ start <= $ end ){
  12. // Formula for calculating the total number of seconds accumulated here: the timestamp number of seconds in the previous month minus the timestamp number 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 a week in a time period. The value belongs to the 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 timestamp
  25. $ Start = strtotime ($ start. '-01 ');
  26. $ End = strtotime ($ end. '-01 ');
  27. $ I = 0;
  28. $ D = array ();
  29. While ($ start <= $ end ){
  30. // Formula for calculating the total number of seconds accumulated here: the timestamp number of seconds in the previous month minus the timestamp number 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 days 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 );


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.