MySQL query field as different data type
Just wondering if there's a way to query a field from a MySQL table as a different data type.
Let's say I have stored a field called duration
which is type i开发者_如何学编程nt() that I want to query using a SELECT(duration) statement, but I want the result formatted as time() data type.
Is this possible?
Regards.
If you have an INT that constitutes a UNIX timestamp, you may use the FROM_UNIXTIME function to convert it to a date string. The resulting string may then be converted to a DATETIME value with the TIMESTAMP function.
For instance you may write:
SELECT TIMESTAMP(FROM_UNIXTIME(1302202070));
Or:
SELECT TIMESTAMP(FROM_UNIXTIME(some_column)) FROM some_table;
精彩评论