Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to store span on time in a MySQL database?

Tags:

mysql

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?

like image 773
GSto Avatar asked Oct 05 '10 20:10

GSto


1 Answers

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.

like image 104
Paul Dixon Avatar answered Oct 04 '22 18:10

Paul Dixon