I need to get the next month with php. Everywhere is written these example
date('Y-m-t', strtotime('+1 month'));
The output of the above code is '2017-03-31'
. I need to get February, not March.
If you want to get the next irrespective of the current date in the current month. below code may help you
echo date('M',strtotime('first day of +1 month'));
// e.g. "Jan"
echo date('m',strtotime('first day of +1 month'));
// e.g. "1"
echo date('F',strtotime('first day of +1 month'));
// e.g. "January"
This will give you Next month.
You can find more formatting masks in date()
function documentation
To get next month using php use string to time function as below:
$nxtm = strtotime("next month");
echo date("M", $nxtm);
Use Like This
// One month from today
$date = date('Y-m-d', strtotime('+1 month'));
// One month from a specific date
$date = date('Y-m-d', strtotime('+1 month', strtotime('2015-01-01')));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With