与MySQL中两个时间字段的分钟差 [英] Difference in minutes from two time fields in MySQL

查看:372
本文介绍了与MySQL中两个时间字段的分钟差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用时间"字段设置了我的MySQL数据库

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

不是传统意义上的HH:MM,它是事件发生的时间,因此,在游戏中还剩下5分45秒时,发生了值为5:45的事件. 12:25发生了,还剩12分25秒,等等.

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 occurred with 5 minutes 45 seconds left in a game. 12:25 occurred with 12 minutes and 25 seconds left, etc.

我希望能够找出经过的总时间,因此,如果我有一个事件发生在12:25,而下一个事件发生在5:45,我希望能够得到差值,等于6:40.然后,我想用十进制表示,在这种情况下为6.67.

I would like to be able to find out the total time elapsed, so if I have an event that occurred at 12:25 and the next event occurred at 5:45 I want to be able to get the difference, which would be equal to 6:40. Then, I would like to express this as a decimal, in this case 6.67.

这可能吗?

提前谢谢.

推荐答案

只需使用

TIMEDIFF(fromtime, totime):

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

如果需要十进制,请使用TIME_TO_SEC()/3600(它假定您将秒传递了十进制,但是存储时间的格式含糊不清,SQL可能会将其解释为HH:MM-您可以使用CONCAT("00:",MinuteSecondField)也许吗?)-那么您可以使用TIME_TO_SEC()/60,这更正确)

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)

这篇关于与MySQL中两个时间字段的分钟差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆