This is a bug according to this post .
Cause. . When we do not specify a date createFromFormat, it will be considered the default by default. So in this case it will be 1996-02-31that which does not exist, and therefore it will take the next month.
Solution: You must provide a day to avoid this scenario.
$date = "2011-02";
echo $date."\n";
$d = DateTime::createFromFormat("Y-m-d",$date."-01");
echo $d->format("Y-m");