What is the best way to store duration in MySQL

I need to store duration (number of minutes and/or hours and/or days). I have looked at MySQL type, but DATE and TIME types seems to be used to store a specific date in time. Not a duration.

I thinking about using a int to store the number of second, and convert it in the PHP for display.


You seem to have the answer yourself. You can store the number of milliseconds(or any unit) in the duration as a number and convert it to the unit that you wish in the application.


您可以将该值存储为一个数字。


您可能不一定需要存储它,如果它是从表中已有的数据计算出来的,则可以运行数学查询:SELECT time1-time2 FROM table_name

链接地址: http://www.djcxy.com/p/10108.html

上一篇: 编写一个将英国日期转换为相对时间的PHP函数

下一篇: 在MySQL中存储持续时间的最佳方式是什么?