TIMESTAMP 的时间范围
· 阅读需 2 分钟
执行 sql 报错。
UPDATE inspection_plans t SET t.plan_end_time = '2041-04-08 10:41:03' WHERE t.id = 1
错误信息:
Data truncation: Incorrect datetime value: '2041-04-08 10:41:03' for column 'plan_end_time' at row 1
问题原因:TIMESTAMP 的范围是 '1970-01-01 00:00:01' UTC 到 '2038-01-19 03:14:07' UTC
解决方法:将 TIMESTAMP 改为 DATETIME 类型。
alter table inspection_plans modify plan_end_time datetime;
总结:
DATE能够表示的时间范围:1000-01-01到9999-12-31,只记录年月日,不存储时分秒TIME能够表示的时间范围:'-838:59:59'到'838:59:59',只记录时分秒,不存储年月日DATETIME能够表示的时间范围:1000-01-01 00:00:00到9999-12-31 23:59:59推荐TIMESTAMP能够表示的时间 范围:1970-01-01 00:00:01 UTC到2038-01-19 03:14:07 UTCYEAR能够表示的时间范围:1901到2155TIMESTAMP和DATETIME的区别:TIMESTAMP是 UTC 时间,存储时会转换为 UTC 时间,取出时会转换为当前时区的时间DATETIME是本地时间,存储时不会转换为 UTC 时间,取出时也不会转换为 UTC 时间