Weird Date Validation I have this validation
'required|date_format:m/Y'
then when I input '02/2016' (Note: That the month has 29 days) it will not return error but if I will input '02/2017' or year that february has only 28 days.. it will return error..
I think its doing something with the current date, and failing now because its the 29th (or 30th, depending where you are).
The validator runs;
DateTime::createFromFormat('m/Y', '02/2017');
Which if I run in Tinker, returns
=> DateTime {#695
+"date": "2017-03-01 23:07:38.000000",
+"timezone_type": 3,
+"timezone": "UTC",
}
ohhh i see.. so it is because the date now.. thank you
Also explained here;
http://stackoverflow.com/questions/36065963/unix-timestamp-from-custom-string-php
See the accepted answer.
This DateTime::createFromFormat('!m/Y', '02/2017');
produces the right result in Tinker
>>> $d = DateTime::createFromFormat('!m/Y', '02/2017');
=> DateTime {#736
+"date": "2017-02-01 00:00:00.000000",
+"timezone_type": 3,
+"timezone": "UTC",
but does not work in validation
I think you might need a custom validation, or prefix your date with 01 and add day into the rule to check.
Please sign in or create an account to participate in this conversation.