I have this type of date:
"Date": "2024-09-06T06:58:19.326Z",
How should I validate it in my FormRequest in Laravel?
I’ve tried this:
'required|date_format:Y-m-dTH:i:s.uZ'
and this:
date_format:Y-m-d
but I get 422 every time.
I have this type of date:
"Date": "2024-09-06T06:58:19.326Z",
How should I validate it in my FormRequest in Laravel?
I’ve tried this:
'required|date_format:Y-m-dTH:i:s.uZ'
and this:
date_format:Y-m-d
but I get 422 every time.
3
Answers
Simply adding this will resolve your issue,
Solution 1:
But if you need some exact solution you can do something like this,
Solution 2:
But the recommended solution is the first one, since it handles most of the date formats. Hope this resolves your issue.
u
from the date format represents microseconds (6 digits). Therefor you need to usev
which represents only milliseconds (3 digits).Therfor the solution would be:
See: https://www.php.net/manual/de/datetime.format.php