1

I'm storing a duration as a decimal 0.5 for half hour, 2 for two hours, and so on. When doing some calculations with times, I need to have this represented in H:i:s, so 0.5 = 00:30:00.

How should I approach this in Mysql? The application is small and not for public consumption, and so I'm not fussed if the solution is hackish.

My goal is to be able to use it in TIMEADD(my_time, duration). Did I miss something in the manual?

4

2 回答 2

1

试试这个查询

select 
   id, 
   type, 
   details,
   duration,
   SEC_TO_TIME(duration*60*60) AS durationInTime 
from 
   tbl

SQL 小提琴

| ID |     TYPE |             DETAILS | DURATION |                 DURATIONINTIME |
-----------------------------------------------------------------------------------
|  1 |    Email | admin@sqlfiddle.com |     10.5 | January, 01 1970 10:30:00+0000 |
|  2 |  Twitter |          @sqlfiddle |        5 | January, 01 1970 05:00:00+0000 |
|  3 | blahblah |                 XYZ |      5.5 | January, 01 1970 05:30:00+0000 |

希望这可以帮助

于 2013-05-14T03:50:13.403 回答
0

尝试这个 :-

select SEC_TO_TIME(0.5*60*60);

输出:-

'00:30:00'
于 2013-05-14T03:55:04.220 回答