PHP add 1 month to date

后端 未结 6 1357
旧巷少年郎
旧巷少年郎 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:54

    Hi In Addition to their answer. I think if you just want to get the next month based on the current date here's my solution.

    $today = date("Y-m-01");
    
    $sNextMonth = (int)date("m",strtotime($today." +1 months") );
    

    Notice That i constantly define the day to 01 so that we're safe on getting the next month. if that is date("Y-m-d"); and the current day is 31 it will fail.

    Hope this helps.

提交回复
热议问题