MySQL学习(六)timestamp & datetime 区别

参考博客: https://cloud.tencent.com/developer/article/1407693
timestamp只使用datetime一半的存储空间,并且会根据时区变化,具有特殊的自动更新能力。另一方面,timestamp允许的时间范围要小得多(1970.1.1-2038年)

  • 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' UTC
  • datetime直接保存不需要转换,timestamp会转变为UTC时间保存在数据库,当select的时候再转变为当前时区的时间
  • datetime存储需要更多的字节,在mysql支持毫秒之前,datetime需要8字节,而timestamp只需要4个字节。
原文地址:https://www.cnblogs.com/lhxBlogs/p/15660927.html