Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I wanted to save a span of time to the database, what data type would I use?

I'd like to save the duration of a game. Something like 1:43:00 or 0:32:12.

What data type should I choose if I'm using Microsoft SQL Server 2008 R2?

like image 842
Only Bolivian Here Avatar asked Feb 23 '23 08:02

Only Bolivian Here


1 Answers

Use an integer type, and just store a quantity for the smallest unit of precision you care about (in this case, seconds). Your client program code should worry about formatting it. So for your two sample values, the stored data would be 6180 and 1932.

To show the values, C# (for example) would use something like TimeSpan.FromSeconds().ToString()

like image 78
Joel Coehoorn Avatar answered Feb 26 '23 04:02

Joel Coehoorn