Q:

get a wrong next month in PHP

Today is 31st May
$currentM = date('m');
// 05

$nextM = date('m', strtotime('+1 month'));
// 07

What am I doing wrong? I don't understand why the next month is giving 07.

A:

The next month from today (31/5) is the 31/6 which doesn't exist, so it forwards to the 1/7.
You may want to increment the actual month: $nextM = date('m') % 12 + 1

A:

try :
$d = new DateTime();
$d->modify('first day of next month');
echo $d->format('m');

