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

后端 未结 28 1787
孤城傲影
孤城傲影 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 08:59

    function first_last_day($string, $first_last, $format) {
        $result = strtotime($string);
        $year = date('Y',$result);
        $month = date('m',$result);
        $result = strtotime("{$year}-{$month}-01");
        if ($first_last == 'last'){$result = strtotime('-1 second', strtotime('+1 month', $result)); }
        if ($format == 'unix'){return $result; }
        if ($format == 'standard'){return date('Y-m-d', $result); }
    }
    

    http://zkinformer.com/?p=134

提交回复
热议问题