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

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

    This should work:

    $week_start = strtotime('last Sunday', time());
    $week_end = strtotime('next Sunday', time());
    
    $month_start = strtotime('first day of this month', time());
    $month_end = strtotime('last day of this month', time());
    
    $year_start = strtotime('first day of January', time());
    $year_end = strtotime('last day of December', time());
    
    echo date('D, M jS Y', $week_start).'
    '; echo date('D, M jS Y', $week_end).'
    '; echo date('D, M jS Y', $month_start).'
    '; echo date('D, M jS Y', $month_end).'
    '; echo date('D, M jS Y', $year_start).'
    '; echo date('D, M jS Y', $year_end).'
    ';

提交回复
热议问题