aausterm aausterm - 7 months ago 92
PHP Question

PHP DateTime November Bug

I am having an issue where using DateTime::createFromFormat() is skipping November. The code I am executing is:

$dateTime = DateTime::createFromFormat('m Y', "11 2016");
return $dateTime->format('F Y');

This keeps returning December 2016. If I change the 11 to 10 it returns October 2016 and if I change it to 12 it returns December 2016. Why is it skipping November?


It's using the current day of the month because you did not specify a day. There is no 31st of November so it uses the next logical day: December 1st.