-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP 8.1 - DateTime::createFromFormat returns false #8652
Comments
Note that this changed in PHP 8.0.10. https://3v4l.org/N2MlJ The docs also match the behavior. https://www.php.net/manual/en/datetime.createfromformat.php
Note the word "preceded", and flipping the modifiers does actually solve the issue. But I'm not sure if this is an accidental or wanted change. Maybe @derickr can clarify. |
You are absolutely right! Evidently I missed the 8.0.10 changes (and the docs which is very clear) |
No problem. Let's keep it open until Derick responds just to make sure this is expected. |
This is expected. The parser works from left to right, and without knowing the year, you don't know whether for example 147 is either May 28 in 2022, or the also correct May 27 in leap years. The fix in 8.0.10 makes this now a hard requirement as per the documentation instead of sometimes giving you the wrong answer (As it would have used the current year, 2022, to calculate the 147th day there). |
Description
The following code (which works perfectly in PHP 8.0:
Resulted in this output:
But I expected this output instead:
The only way to make it work is to swap day of the year and year.
PHP Version
PHP 8.1.6
Operating System
Ubuntu Server 18.04
The text was updated successfully, but these errors were encountered: