Max msyql datetime value | Error 22007, 1292
When trying to insert into a DATETIME
column you might have gotten an error like:
Incorrect datetime value: '2038-03-28 17:51:34' for column 'expires_at' at row 1
Well, that's probably because your column is a TIMESTAMP
which has a maximum value of '2038-01-19 03:14:07' UTC
& otherwise seems to work much like a date/datetime column.
Update your database to use a DATETIME
column instead of a TIMESTAMP
column & you should be good to go.
See mysql datetime documentation
If this isn't your issue
- You may have invalid date, like April 31 or 2:30 am on a daylight-savings switch day. See https://stackoverflow.com/questions/35602939/mysql-1292-incorrect-datetime-value
- You may have an incorrect format. It's supposed to be
YYYY-MM-DD HH:MM:SS
See https://sebhastian.com/mysql-incorrect-datetime-value/- in PHP, this is can be output with
DateTime
using$date->format('Y-m-d H:i:s');
- in PHP, this is can be output with
- You may need to disable
NO_ZERO_DATE
or make the column nullable. See https://dba.stackexchange.com/questions/287286/1292-incorrect-datetime-value-when-updating-an-empty-datetime-field