Home > Net >  How to divide hour to minute in MySQL?
How to divide hour to minute in MySQL?

Time:05-06

I have a table Time with column StartTime:

ID StartTime
1 08:00:00

Now I want to find the time difference between StartTime and 09:00:00, divide it by 3 to result in 20min. How can I do something like this?

SELECT ('09:00:00' - (SELECT StartTime FROM Time) / 3)

Output should be '00:20:00'

CodePudding user response:

A combination OF TIMEDIFF and TIME_TO SEC and SEC_TO_TIME

select SEC_TO_TIME(TIME_TO_SEC(timediff('09:00:00','08:00:00')) / 3)
| SEC_TO_TIME(TIME_TO_SEC(timediff('09:00:00','08:00:00')) / 3) |
| :------------------------------------------------------------ |
| 00:20:00.0000                                                 |

db<>fiddle here

  • Related