PHP add 1 month to date

后端 未结 6 1353
旧巷少年郎
旧巷少年郎 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条回答
  •  自闭症患者
    2020-12-19 15:40

    there are 3 options/answers

         $givendate is the given date (ex. 2016-01-20)
    
    option 1:
            $date1 = date('Y-m-d', strtotime($givendate. ' + 1 month'));
    
    option 2:
            $date2 = date('Y-m-d', strtotime($givendate. ' + 30 days'));
    
    option 3:
            $number = cal_days_in_month(CAL_GREGORIAN, date('m', strtotime($givendate)), date('Y', strtotime($givendate)));
            $date3 = date('Y-m-d', strtotime($date2. ' + '.$number.' days'));
    

提交回复
热议问题