MySQL存储持续时间-数据类型? [英] MySQL storing duration time - datatype?
本文介绍了MySQL存储持续时间-数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要计算用户在网站上花费的时间.注销时间和登录时间之间的区别是给我类似"X先生花了4个小时43分钟".所以要存储4小时43分钟,我这样声明:
duration
时间NOT NULL
I need to calculate the time a user spends on site. It is difference between logout time and login time to give me something like "Mr X spent 4 hours and 43 minutes online". So to store the4 hours and 43 minutes i declared it like this:
duration
time NOT NULL
这是有效的还是更好的存储方式?我需要存储在数据库中,因为我还有其他计算需要在其他+用例中使用.
Is this valid or a better way to store this? I need to store in the DB because I have other calculations I need to use this for + other use cases.
推荐答案
将其存储为整数秒数将是最好的方法.
Storing it as an integer number of seconds will be the best way to go.
-
UPDATE
将简洁明了-即duration = duration + $increment
- 如Tristram所述,使用限制
TIME
字段-例如"TIME
值的范围可以从'-838:59:59'
到'838:59:59'
" - 天/小时/分钟/秒的显示格式不会被硬编码.
- 使用整数秒数"字段时,几乎可以肯定地执行其他计算.
- The
UPDATE
will be clean and simple - i.e.duration = duration + $increment
- As Tristram noted, there are limitations to using the
TIME
field - e.g. "TIME
values may range from'-838:59:59'
to'838:59:59'
" - The days/hours/minutes/seconds display formatting won't be hardcoded.
- The execution of your other calculations will almost surely be clearer when working with an integer "number of seconds" field.
这篇关于MySQL存储持续时间-数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文