PHP add 1 month to date

后端 未结 6 1355
旧巷少年郎
旧巷少年郎 2020-12-19 15:23

I\'ve a function that returns url of 1 month before.

I\'d like to display current selected month, but I cannot use simple current month, cause when user clicks link

6条回答
  •  梦毁少年i
    2020-12-19 15:40

    Date difference

    $date1 = '2017-01-20';
    $date2 = '2019-01-20';
    
    $ts1 = strtotime($date1);
    $ts2 = strtotime($date2);
    
    $year1 = date('Y', $ts1);
    $year2 = date('Y', $ts2);
    
    $month1 = date('m', $ts1);
    $month2 = date('m', $ts2);
    
    echo $joining_months = (($year2 - $year1) * 12) + ($month2 - $month1);
    

提交回复
热议问题