开发者

MySQL: Convert INT to DATETIME

开发者 https://www.devze.com 2022-12-22 04:25 出处:网络
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?

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?

(I found t开发者_JAVA百科he answer when re-scanning the MySQL Date functions, but didn't see the answer on SO. Figured it should be here.)


FROM_UNIXTIME()


select from_unixtime(column,'%Y-%m-%d') from myTable; 


SELECT  FROM_UNIXTIME(mycolumn)
FROM    mytable


The function STR_TO_DATE(COLUMN, '%input_format') can do it, you only have to specify the input format. Example : to convert p052011

SELECT STR_TO_DATE('p052011','p%m%Y') FROM your_table;

The result : 2011-05-00


This works for sure.

select from_unixtime(column) from table
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号