PHP determines how many days of the month

Source: Internet
Author: User


  1. /**
  2.  * determine how many days a certain month of a year
  3.  * @return [Type][description]
  4. */
  5. function DaysInMonth ($year = ', $month = ') {
  6. if (empty ($year)) $year = Date (' Y ');
  7. if (empty ($month)) $month = Date (' m ');
  8. if (In_array ($month, Array (1, 3, 5, 7, 8, ' 01 ', ' 03 ', ' 05 ', ' 07 ', ' 08 ', 10, 12))) {
  9. $text = ' 31 '; // month-old
  10. }elseif ($month = = 2 | | $month = = ' 02 ') {
  11. if (($year% 400 = = 0) | | (($year% 4 = = 0) && ($year% 100!== 0))) { // to determine if a leap Year
  12. $text = ' 29 '; // Leap Year 2 Month
  13. }else {
  14. $text = ' 28 '; // Common year 2 Month
  15. }
  16. }else {
  17. $text = ' 30 '; // Month Small
  18. }
  19. return $text;

21.}


/**

    1.  * determine how many days a certain month of a year
    2.  * @return [Type][description]
    3.  */
    4. function daysInmonth1 ($year = ', $month = ') {
    5. if (empty ($year)) $year = Date (' Y ');
    6. if (empty ($month)) $month = Date (' m ');
    7. $day = ' 01 ';
    8. // whether the detection date is legal
    9. if (!checkdate ($month, $day, $year)) return ' entered in the wrong time ';
    10. // gets the timestamp of the first day of the current month ( hours , minutes , seconds , months , Day , years )
    11. $timestamp = Mktime (0,0,0, $month, $day, $year);
    12. $result = date (' t ', $timestamp);
    13. return $result;

16.}

PHP determines how many days of the month

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.