I am trying to set the date format as (d-m-Y), but error message says as stated below:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: '20-03-2020'
Below is my Controller validation code
$request->validate([
'date' => 'required|date_format:d-m-Y',
]);
I also tried to set the format in my model, which was also futile
protected $dateFormat = 'd-m-Y';
How can I set the date_format?
Y-m-d, you try to addd-m-Y, that's what this error is trying to tell you. Change the format back toY-m-dwhen you insert data in your databaseDateTime::createFromFormat('!d-m-Y', "20-03-2020")->format('d-m-Y') == "20-03-2020";return true. So the validation is passed. I think kerbholz is right. You need to post your table column's type.