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

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

    There are ways to get last day of month.

    //to get last day of current month
    echo date("t", strtotime('now'));
    
    //to get last day from specific date
    $date = "2014-07-24";
    echo date("t", strtotime($date));
    
    //to get last day from specific date by calendar
    $date = "2014-07-24";
    $dateArr=explode('-',$date);
    echo cal_days_in_month(CAL_GREGORIAN, $dateArr[1], $dateArr[0]); 
    

提交回复
热议问题