We currently store the hours, minutes part separately to capture time (e.g. 10.30, 14.30). Is this the best way to model time representation (supported databases are h2, mysql, postgres)
A:
In the database I would create an integer field that contains the number of minutes. Then the UI would have to convert to and from the integer field.
But 1) total time calculations would be so much faster (questions like give me total time spent on x, average time on y).
2) Disk space requirements would go down. If the tables contains less than a billion rows it does not matter much.
What happens if you want to store seconds as well, at some point in the future?
If you are running SQL Server 2008 or above, you could also use the new TIME data type, as in
DECLARE myTime TIME(0)
or
CREATE TABLE #T
( TableID INT IDENTITY(1,1)
, StartTime TIME(0)
)
INSERT INTO #t (StartTime) VALUES ('12:04:59')
SELECT top 10000 * FROM #t
Henrik Staun Poulsen
2010-08-26 09:20:43
don't intend to store seconds in the near future
2010-08-26 10:26:11
2010-08-26 10:28:09