开发者

MySQL query field as different data type

开发者 https://www.devze.com 2023-02-23 08:39 出处:网络
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 que

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;
0

精彩评论

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