PHP add 1 month to date

后端 未结 6 1354
旧巷少年郎
旧巷少年郎 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 16:01

    You can simple use the strtotime function on whatever input you have to arrive at April 2012 then apply the date and strtotime with an increment period of '+1 month'.

    $x = strtotime($t);
    $n = date("M Y",strtotime("+1 month",$x));
    echo $n; 
    

    Here are the relevant sections from the PHP Handbook:

    http://www.php.net/manual/en/function.date.php

    https://secure.php.net/manual/en/function.strtotime.php

    This solution solves the additional issue of incrementing any amount of time to a time value.

提交回复
热议问题