What is the minimum date time value that can be entered in MySQL column of timestamp datatype?

oxosxuxt  于 2022-12-22  发布在  Mysql
关注(0)|答案(1)|浏览(135)

I'm trying to insert a date time value e.g. 1970-01-01 00:00:01 in a column of timestamp datatype in MySQL table but getting following error:
#1292 - Incorrect datetime value: '1970-01-01 00:00:01' for column 'order_date' at row 1

But according to MySQL docs - The TIMESTAMP value has a range from '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
So if the range value starts from 1970-01-01 00:00:01 UTC then why this value can't be inserted in the table? Is there something to do with UTC ? What will be the minimum date time value for timestamp that can be inserted without any issue?

nbysray5

nbysray51#

Timestamp columns store a utc value and start at 1970-01-01 00:00:01, but whenever you read or write them, they convert to/from your session timezone. This makes them something of a nightmare to work with if you are actually intending to only use UTC.
Just use a datetime type if you ever are trying to set particular times that come from your client. If you must use timestamp and want to set a particular UTC time, first do:

set session time_zone='+00:00';

But note that any client that doesn't do that may see a different time. Even if you set your server timezone to UTC, so that sessions default to UTC, some client libraries "helpfully" set the session timezone when they connect.

相关问题