Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to divide hour to minute in MySQL?

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'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading