This is only happening on the 31st so far
echo date('F',strtotime('this month')); //May
echo date('F',strtotime('next month'));//July
echo date('F',strtotime('+1 month'));//July
As far as I understand June comes after May. But i'm guessing php is being lazy in just adding 31 days from now, skipping an entire month.
How can I safely get the next month regardless of lenght? Ideally using strttotime
edit Forgot to mention, why i was hoping to use strtotime is that I'm using a search box to find events inter开发者_高级运维preting user input strtotime
The most robust way is probably:
date('F', mktime(0, 0, 0, date('n') + 1, 1))
You can also use:
echo date('Y-m-d', strtotime("first day of -1 month"));
This is because of the date overflow in how PHP handles the date. It just increases the month by 1. There is no 31st of June so so it resolves it by adding a day on which then puts it into July. Try converting it to the first of the month and then incrementing the month.
This is a bug, but due to the way it is and how long it's been there it's marked as wontfix. https://bugs.php.net/bug.php?id=66988
精彩评论