Invalid datetime format: 1292 Invalid datetime value - Laravel 5.2

I am getting this error when I insert this value into my database table:

SQLSTATE [22007]: Invalid datetime format: 1292 Incorrect datetime value:
'24 / 06/2017 'for column' registration_from 'at row 1 
(SQL: insert into `campus_registrations` (` campus_major_class_id`, 
`registration_from`,` registration_to`, `testing`,` announcement`, 
`enrollment_from`,` enrollment_to`, `updated_at`,` created_at`) values ​​(3, 
24/06/2017, 27/06/2017, 13/07/2017, 01/08/2017, 05/09/2017, 31/01/2018,
 2017-06-07 09:39:31, 2017-06-07 09:39:31))

Do I have to set the date or time first?

+4


source to share


6 answers


The error is here:

Incorrect datetime value: '24/06/2017' for column 'registration_from' at row 1

      



the default format for a column date

in mysql is Y-m-d

, and for datetime

a Y-m-d H:i:s

. So please change the date in this format and try again.

+5


source


Since you are not using the standard datetime format, define a mutator for each date. For example:



public function setRegistrationFromAttribute($value)
{
    $this->attributes['registration_from'] =  Carbon::parse($value);
}

      

+7


source


I got the same error when trying to register user from vue js frontend to laravel frontend API.

The solution was to upgrade mysql strict mode to false. If anyone knows the cons of this approach, please leave your comments!

//config/database.php
'mysql' => [
    'strict' => false,
]

      

+6


source


I got the same problem and finally I got it resolved. You can add some lines of code at the end of add.blade.php

 $('.date-picker').datepicker({
                format: 'yy/mm/dd',
                autoclose: true,
                todayHighlight: true
            });

      

+1


source


Link

MYSQL recognizes a date value in the format YYYY-MM-DD

or YY-MM-DD

. You can use /

. This 24/06/2017

is considered invalid. Try2017/06/24

0


source


This was happening to me in Laravel 5.6 until I changed the code $table->date('last_date')->default(now());

0


source







All Articles