How to find the last day of the month from date?

后端 未结 28 1796
孤城傲影
孤城傲影 2020-11-22 08:56

How can I get the last day of the month in PHP?

Given:

$a_date = \"2009-11-23\"

I want 2009-11-30; and given

$a_dat         


        
28条回答
  •  野性不改
    2020-11-22 09:04

    Here is a complete function:

    public function get_number_of_days_in_month($month, $year) {
        // Using first day of the month, it doesn't really matter
        $date = $year."-".$month."-1";
        return date("t", strtotime($date));
    }
    

    This would output following:

    echo get_number_of_days_in_month(2,2014);
    

    Output: 28

提交回复
热议问题