user457015
user457015

Reputation: 981

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.

Upvotes: 7

Views: 3273

Answers (3)

user685515
user685515

Reputation: 21

You can store the value as a number.

Upvotes: 1

Damon
Damon

Reputation: 10818

You might not necessarily need to store it, either, if it's being calculated from data already in your table you could run a math query: SELECT time1-time2 FROM table_name

Upvotes: -1

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103155

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.

Upvotes: 7

Related Questions