What is the internal representation of timestamp values in MySQL

只谈情不闲聊 提交于 2019-12-12 03:09:55

问题


I have a .dat file that represents a Table in a database and has a particular column for timestamp values. Now the values are stored in the following way: -

978302039

I'm required to copy all the elements into another table, but I'm not sure if the column containing these values should be of int or timestamp. As far as I know, we store timestamp values in the following format: -

1000:09:12 00:00:00

But these values stored here don't look anything like that. Is there any internal representation of timestamp values?


回答1:


Per MySQL Documentation

MySQL recognizes TIMESTAMP values in these formats:

As a number in either YYYYMMDDHHMMSS or YYMMDDHHMMSS format, provided that the number makes sense as a date. For example, 19830905132800 and 830905132800 are interpreted as '1983-09-05 13:28:00'.

With that, the value you have posted looks like a invalid timestamp to me.




回答2:


978302039 looks like a unix timestamp in seconds. You can convert it to MySQLs DATETIME with the FROM_UNIXTIME() function.

SELECT FROM_UNIXTIME(978302039)

will return something like

2000-12-31 22:33:59

The exact value depends on the timezone configuration of your server.



来源:https://stackoverflow.com/questions/39597630/what-is-the-internal-representation-of-timestamp-values-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!