将时间跨度存储在MySQL数据库中的最佳方法?
问题描述:
我想在mysql数据库中存储某些内容的时间,例如某时间所花费的时间,例如2小时,5分钟,10秒.精度低至秒是首选,但不是必需的.最好的方法是什么?
I'd like to store an amount of time for something in a mysql database,for the length of time something took, such as 2 hours, 5 minutes, 10 seconds. accuracy down to the second is preferred, but not required. What's the best way to go about doing this?
答
A MySQL TIME type can store time spans from '-838:59:59' to '838:59:59' - if that's within your required range, and it would be useful to have MySQL natively present these spans in HH:MM:SS form, then use that.
否则,我将使用整数类型来表示秒数.
Otherwise, I'd just go with an integer type to represent the number of seconds.