MySQL how to convert decimal value to degree, minute, second

前端 未结 3 1550
萌比男神i
萌比男神i 2021-01-27 04:54

I have a decimal value say 123.77

Now i want to convert it into corresponding degree, minute, second value using MySQ

3条回答
  •  萌比男神i
    2021-01-27 05:18

    Thinking out of the box, by borrowing a different Babylonian-based metric:

    mysql> SELECT TIME_FORMAT("%H°%i'%s", SEC_TO_TIME(ROUND(3600 * -1.234)));
    +-------------------------------------------------------------+
    | TIME_FORMAT("%H°%i'%s", SEC_TO_TIME(ROUND(3600 * -1.234)))  |
    +-------------------------------------------------------------+
    | -01:14:02                                                   |
    +-------------------------------------------------------------+
    mysql> SELECT TIME_FORMAT("%H°%i'%s", SEC_TO_TIME(ROUND(3600 * -123.77)));
    +--------------------------------------------------------------+
    | TIME_FORMAT("%H°%i'%s", SEC_TO_TIME(ROUND(3600 * -123.77)))  |
    +--------------------------------------------------------------+
    | -123:46:12                                                   |
    +--------------------------------------------------------------+
    

    (The ROUND is to avoid getting 3 decimal places in the answer.)

提交回复
热议问题