在MYSQL中将时间戳转换为日期时间

在MySQL中将时间戳转换为datetime时会丢失任何数据吗?两者之间的主要区别是什么?

已邀请:

inisi

赞同来自:

在冒险进行转换之前,您可以创建一个额外的列和一个查询来将数据复制到该列中。

gipsam

赞同来自:

  1. 不,不。如果将datetime或timestamp转换为date(因为date不存储时间数据),您将丢失数据。
  2. 有关两者之间差异的详细信息,您可以阅读this question

seaque

赞同来自:

从文档(TIMESTAMP Propeties):

TIMESTAMP values are converted from the current time zone to UTC for storage, and converted back from UTC to the current time zone for retrieval. (This occurs only for the TIMESTAMP data type, not for other types such as DATETIME.) By default, the current time zone for each connection is the server's time. [...] If you store a TIMESTAMP value, and then change the time zone and retrieve the value, the retrieved value is different from the value you stored. This occurs because the same time zone was not used for conversion in both directions.

要回复问题请先登录注册