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

后端 未结 28 1482
孤城傲影
孤城傲影 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:20

    Try this , if you are using PHP 5.3+,

    $a_date = "2009-11-23";
    $date = new DateTime($a_date);
    $date->modify('last day of this month');
    echo $date->format('Y-m-d');
    

    For finding next month last date, modify as follows,

     $date->modify('last day of 1 month');
     echo $date->format('Y-m-d');
    

    and so on..

提交回复
热议问题