MySQL: Convert INT to DATETIME

MysqlDatetime

Mysql Problem Overview


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 the answer when re-scanning the MySQL Date functions, but didn't see the answer on SO. Figured it should be here.)

Mysql Solutions


Solution 1 - Mysql

Solution 2 - Mysql

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

Solution 3 - Mysql

SELECT  FROM_UNIXTIME(mycolumn)
FROM    mytable

Solution 4 - Mysql

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

Solution 5 - Mysql

This works for sure.

select from_unixtime(column) from table

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionpix0rView Question on Stackoverflow
Solution 1 - MysqlRobView Answer on Stackoverflow
Solution 2 - Mysqluser2970312View Answer on Stackoverflow
Solution 3 - MysqlQuassnoiView Answer on Stackoverflow
Solution 4 - MysqlybenhssaienView Answer on Stackoverflow
Solution 5 - MysqlVahan KarapetyanView Answer on Stackoverflow