framework: [5.4] Validation Rule: date_format bug
As the title says, I may be missing something. The scenario is provided below.
Versions used
Laravel Version: 5.4.3 PHP Version: 7.0.15 Database Driver & Version: MariaDB 10.1.20
Problem
The Laravel ‘date_format’ validation rule on Requests fail on the date ‘2017-02’. It fails on non leap years when using the month ‘02’ (February).
Test Data
Working on the following dates [Validation is successful]
2016-01 2016-02 2020-02 2024-02
Not working on the following dates [Validation does not match the format Y-m]
2013-02 2017-02 2021-02
Steps to Reproduce
Create a request with the following rule
return ['testDate' => ['bail', required, 'date_format:Y-m']];
Next steps
Create a sample input form, route, and controller that uses the request created. Input the test data provided above. Input test data ‘2017-02’. Expected: Validation Passed, Actual: Does not match the format Y-m
Other notes
The validation rule ‘date’ works properly even on non leap years when using the month ‘02’ (February). Tested on Laravel 5.3, same error.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 21 (12 by maintainers)
Commits related to this issue
- #17642 - Reset day parameter when using Y-m (#20566) * #17642 - Reset day parameter when using Y-m * Update ValidatesAttributes.php — committed to laravel/framework by BramRoets 7 years ago
Just ran into this myself when trying to use
date_format:Y-mas a validation rule. 😭For those interested, I ended up just using the
datevalidation rule instead.@themsaid @MiSAKACHi @fernandobandeira
Fun fact: As it is now 1st February this problem has now disappeared 😉
Roll your clock back to yesterday and run the above again… hehe.