MySQL:将 INT 转换为 DATETIME
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2367603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL: Convert INT to DATETIME
提问by pix0r
I have a UNIX-type timestamp stored in an INT
column in MySQL. What is the proper way to retrieve this as a MySQL DATETIME
?
我INT
在 MySQL 的一列中存储了一个 UNIX 类型的时间戳。将其作为 MySQL 检索的正确方法是什么DATETIME
?
(I found the answer when re-scanning the MySQL Date functions, but didn't see the answer on SO. Figured it should be here.)
(我在重新扫描 MySQL 日期函数时找到了答案,但在 SO 上没有看到答案。认为它应该在这里。)
回答by Rob
回答by user2970312
select from_unixtime(column,'%Y-%m-%d') from myTable;
回答by Quassnoi
SELECT FROM_UNIXTIME(mycolumn)
FROM mytable
回答by yoben
The function STR_TO_DATE(COLUMN, '%input_format')can do it, you only have to specify the input format. Example : to convert p052011
函数STR_TO_DATE(COLUMN, '%input_format')可以做到,你只需要指定输入格式。示例:转换 p052011
SELECT STR_TO_DATE('p052011','p%m%Y') FROM your_table;
The result : 2011-05-00
结果:2011-05-00