'0000-00-00 00:00:00' 无法赋值给 timestamp 类型
如下为官方文档说法:
The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
'1970-01-01 00:00:01' 同样无法赋值给 timestam 类型,报如下错误:
Incorrect datetime value: '1970-01-01 00:00:01' for column
问题关键在于 UTC,当将TIMESTAMP值插入到表中时,MySQL会将其从连接的时区转换为UTC后进行存储。当查询TIMESTAMP值时,MySQL会将UTC值转换回连接的时区。
故,timestamp 在中国(UTC+8)接受 时间范围为 '1970-01-01 08:00:01' ~ '2038-01-19 11:14:07'
经验证,如下官方文档说明无效:
MySQL does not accept TIMESTAMP values that include a zero in the day or month column or values that are not a valid date. The sole exception to this rule is the special “zero” value '0000-00-00 00:00:00'.