patternsqlMinor
Storing time with milliseconds in database
Viewed 0 times
millisecondswithtimedatabasestoring
Problem
Just a quick question regarding storing "time" in a database. I'm logging the time of users runs which are in the format 00:00:00:00 (hours, minutes, seconds, milliseconds).
I was originally going to store it as
I will be storing the actual time taken from the users stopwatch, not the time when they ran and finished (this will be calculated before being inserted).
What would be the best field type to use? I was thinking either
I was originally going to store it as
TIME but then I realised MySQL doesn't support milliseconds in this type.I will be storing the actual time taken from the users stopwatch, not the time when they ran and finished (this will be calculated before being inserted).
What would be the best field type to use? I was thinking either
double or float, but I'm not sure that would work?Solution
Personally, I'd use integer types for duration
Example: 340,000 milliseconds is 340000 in an unsigned int column.
To me, datetime, time, date etc are for explicit points in time. 340 seconds is meaningless in that context. Having a start
Example: 340,000 milliseconds is 340000 in an unsigned int column.
To me, datetime, time, date etc are for explicit points in time. 340 seconds is meaningless in that context. Having a start
date/time allows the duration to be added of courseContext
StackExchange Database Administrators Q#10400, answer score: 7
Revisions (0)
No revisions yet.