How to get all months between two dates in PHP?

前端 未结 6 1886
旧巷少年郎
旧巷少年郎 2021-01-29 16:41

I have 2 dates. I want to get all months with total days in each.

How can I do this in PHP?

For example

$date1 = \'2013-11-13\'         


        
6条回答
  •  自闭症患者
    2021-01-29 17:31

    i used timestamp and date:

    $date1 = '2013-11-15'; // yy-mm-dd format
    $date2 = '2014-02-15';
    
    $d1 = strtotime('2013-11-15');
    $d2 = strtotime('2014-02-15');
    
    while ($d1 <= $d2) {
        echo date('m-d-Y', $d1)." | ";
        echo cal_days_in_month(CAL_GREGORIAN, date('m', $d1), date('Y', $d1)) ."
    "; $d1 = strtotime("+1 month", $d1); }

提交回复
热议问题