在MySQL中存储时间间隔值的最佳方法? [英] Best way to store time interval values in MySQL?
问题描述
愚蠢的简单问题,但我一直找不到理想的解决方案.我想将时间间隔存储在MySQL列中,例如:
Stupid easy problem, but I haven't been able to find an elegant solution. I want to store time intervals in a MySQL columns, for instance:
1:40(持续1小时40分钟) 0:30(30分钟).
1:40 (for one hour, 40 minutes) 0:30 (30 minutes).
然后可以运行查询,对它们求和.现在,我将它们存储为INT值(1.40),但是我必须手动执行加法操作(除非我缺少一种更简单的方法).
Then be able to run queries, summing them. Right now I store them as INT values (1.40), but I have to manually do the addition (unless I'm missing an easier way).
时间"列类型最多只能存储900小时(我认为大约),因此(几乎)对我来说毫无用处,因为我要跟踪数十万小时以上的时间(我存储一个字段并包含许多不同条目的总和).
The TIME column type only stores upto 900 hours (about, I think), so that's (almost) useless for me since I am tracking upwards of hundreds of thousands of hours (I store one field with a summation of many different entries).
谢谢!
推荐答案
仅存储分钟,因此1:40被存储为100.这使得添加变得容易:100 + 30 = 130.转换回小时:分钟. 130分钟-> 2:10.
store just the minutes, so 1:40 gets stored as 100. this makes for easy addition: 100 + 30 = 130. when you display, do the math to convert back to hours:minutes. 130 minutes -> 2:10.
这篇关于在MySQL中存储时间间隔值的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!