how to get the number of days of the current month? in PHP

后端 未结 11 1881
悲哀的现实
悲哀的现实 2021-02-12 03:35

i want to check if today is the last day of the month, but i don\'t really know how. i want to write it in php.

can you help?

thanks, Sebastian

相关标签:
11条回答
  • 2021-02-12 04:17
    $date = new DateTime('last day of this month');
    $numDaysOfCurrentMonth = $date->format('d');
    
    0 讨论(0)
  • 2021-02-12 04:19

    Use date function:

    if (date('t') == date('j'))
    {
       ...
    }
    
    0 讨论(0)
  • 2021-02-12 04:22

    this is to find the days in any month:

    $days = intval(date('t', strtotime($desiredDate)));
    
    0 讨论(0)
  • 2021-02-12 04:23

    date('t');

    or you may use

    cal_days_in_month.

    see here: http://php.net/manual/en/function.cal-days-in-month.php

    0 讨论(0)
  • 2021-02-12 04:23

    And here it is, wrapped up as a function:

    function is_last_day_of_month($timestamp = NULL) {
        if(is_null($timestamp))
            $timestamp = time();
        return date('t', $timestamp) == date('j', $timestamp);
    }
    
    0 讨论(0)
提交回复
热议问题