mysql相隔多长时间,在MySQL中存储时间间隔值的最佳方法?

博主分享了在MySQL中存储时间间隔的问题,目前使用INT类型存储如1.40这样的值来代表1小时40分钟,但发现手动计算不便。提出了将时间转换为分钟存储,例如1:40存储为100的方法,这样可以简化加法操作。在展示时再转换回小时:分钟格式,如130分钟显示为2:10。
摘要由CSDN通过智能技术生成

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 (for one hour, 40 minutes)

0:30 (30 minutes).

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).

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).

Thanks!

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值