What is the best way to store duration in MySQL?

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

I am thinking of using int to store the number of seconds and converting it to PHP for display.

+7
php mysql
source share
3 answers

You seem to have the answer yourself. You can save the number of milliseconds (or any device) as a number and convert it to the device you want in the application.

+7
source share

You can save the value as a number.

+1
source share

You may not need to store it, if it is calculated from the data already in your table, you can run a mathematical query: SELECT time1-time2 FROM table_name

-one
source share

All Articles