Kiyarash
Kiyarash

Reputation: 2578

Incorrect datetime value 1292 Laravel 5.7 just from a specific date

I saw this error in questions and answers, but my case is a little bit weird!

I'm using Laravel 5.7 with these database settings:

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
        ],

One of my tables records has the user birth date with the timestamp format.

This works fine till the user age is smaller than 1969-02-22 00:00:00. It means 1970-02-22 00:00:00 is OK, but the first one causes an error!

How can I fix this case?

Upvotes: 0

Views: 179

Answers (1)

nbk
nbk

Reputation: 49375

You have Unix time:

It is the number of seconds that have elapsed since the Unix epoch, that is the time 00:00:00 UTC on 1 January 1970,

If you have to save dates prior, use another datatype such as DATE or DATETIMTE.

As you can read here.

Upvotes: 4

Related Questions