Haythem Dridi
Haythem Dridi

Reputation: 118

Laravel : Invalid datetime format: 1292 Incorrect datetime value: '2021-03-14 02:00:00'

i received a lots of invalid datetime format errors

[2021-03-14 02:00:00] production.ERROR: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2021-03-14 02:00:00' for column `xxxxxxx`.`users`.`last_activity` at row 1 (SQL: update `users` set `last_activity` = 2021-03-14 02:00:00, `users`.`updated_at` = 2021-03-14 02:00:00 where `id` = 2561) {"userId":2561,"exception":"[object] (Illuminate\\Database\\QueryException(code: 22007): SQLSTATE[22007]:
[stacktrace]


[2021-03-14 02:58:46] production.ERROR: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2021-03-14 02:58:46' for column `xxxx`.`posts`.`updated_at` at row 1 (SQL: update `posts` set `view` = `view` + 1, `posts`.`updated_at` = 2021-03-14 02:58:46 where `id` = 43018) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 22007): SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2021-03-14 02:58:46' for column `xxxx`.`posts`.`updated_at` at row 1 (SQL: update `posts` set `view` = `view` + 1, `posts`.`updated_at` = 2021-03-14 02:58:46 where `id` = 43018) at /home/xxxx/xxxxx/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, PDOException(code: 22007): SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2021-03-14 02:58:46' for column `xxxx`.`posts`.`updated_at` at row 1 at /home/xxxx/xxxx/vendor/laravel/framework/src/Illuminate/Database/Connection.php:483)
[stacktrace]

The errors started at: 2021-03-14 02:00:00

And ended at: 2021-03-14 02:58:46

Everything worked fine for over a year

All is back to normal without any code change.

Can someone help me understand what's happening?

config/app.php :

  1. 'timezone' => 'Africa/Tunis',

Table structure :

enter image description here Database server :

Upvotes: 2

Views: 2302

Answers (1)

patricus
patricus

Reputation: 62398

The issue is because of Daylight Saving Time (DST).

Your app is set to "Africa/Tunis", which I don't believe recognizes DST. But this is a database error, not an app error. Your database is apparently using a timezone that recognizes DST.

DST started on 2021-03-14 at 02:00:00. Because of this, times between 2021-03-14 02:00:00 and 2021-03-14 02:59:59 do not exist, and are not valid times, thus causing the errors you received.

Upvotes: 5

Related Questions