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

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

    An other way using mktime and not date('t') :

    $dateStart= date("Y-m-d", mktime(0, 0, 0, 10, 1, 2016)); //2016-10-01
    $dateEnd = date("Y-m-d", mktime(0, 0, 0, 11, 0, 2016)); //This will return the last day of october, 2016-10-31 :)
    

    So this way it calculates either if it is 31,30 or 29

提交回复
热议问题