1

My table does an addition of how much time it takes to finish production.

It spits out values like: 192.5, or 100.25.

I'd like to know how to turn these values into something like this:

120 ---> 120 minutes

140.5 ---> 2 hours, 20 minutes, 30 seconds

30.25 ---> 30 mintes, 15 seconds

The formatting is unimportant, just would like to display time.

4

2 回答 2

1

Crudely (I suspect that this can be written more elegantly)...

SET @x = 30.25;

SELECT FLOOR(@x/60) hours
     , FLOOR((@x/ 60-FLOOR(@x/60)) * 60) minutes
     , ROUND(((((@x/60)-FLOOR(@x/60))*60)-FLOOR((@x/60-FLOOR(@x/60))*60))*60,0) seconds;
+-------+---------+---------+
| hours | minutes | seconds |
+-------+---------+---------+
|     0 |      30 |      15 |
+-------+---------+---------+
于 2020-01-10T10:04:25.377 回答
1
DATE_FORMAT('2020-01-01' + INTERVAL `field` * 60 SECOND, '%H:%i:%s')

或者

DATE_FORMAT('2020-01-01' + INTERVAL `field` * 60 SECOND, '%H hours %i minutes %s second')

甚至

TRIM(LEADING '00 hours ' FROM DATE_FORMAT('2020-01-01' + INTERVAL `field` * 60 SECOND, '%H hours %i minutes %s second'))
于 2020-01-10T10:21:58.853 回答