Difference in minutes from two time fields in MySQL

后端 未结 4 1214
执笔经年
执笔经年 2020-11-29 09:47

I set up my MySQL database with the field \'time\'

It is not HH:MM in the traditional sense, it is the time an event occurred, so an event with the value of 5:45 occ

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 10:49

    Just use

    TIMEDIFF(fromtime, totime):
    
    SELECT TIMEDIFF("12:25", "5:45");
    

    If you need a decimal, use TIME_TO_SEC()/3600 (it assumes you passed it seconds, but the format you're storing the times in is vague and SQL probably will interpret them as HH:MM - you can fix this with CONCAT("00:",MinuteSecondField) maybe?) - then you can use TIME_TO_SEC()/60, which is more correct)

提交回复
热议问题