I’m going to be logging the time it takes to process a REST request and I’m undecided on which data type would be best for the column. The time difference would be in the millisecond scale, where I wouldn’t expect it to be less than 1ms but could be a couple seconds (certianly hope it won’t be higher!).
Very similar to Best way to store span on time in a MySQL database?, but while having a higher precision.
I believe I have two options: timestamp or integer. Timestamp has microsecond precision and integer could have any practical precision I need (would just multiply time diff by Y * 1000).
The time difference will be calculated in PHP by
$start = microtime(true);
// do something
$runtime = microtime(true) - $start;
Which data type would be best to store a time difference on the millisecond scale in MySQL?
What are the pros/cons of timestamp and integer for this situation?
The timestamp is used to store a moment in time, not a duration of time.
TIMESTAMPdoesn’t store milliseconds and neither willTIME. Go with an integer field.I also found a similar question: Storing microseconds in MySQL: which workaround?.