Reputation: 21620
I am looking for a way to extract difference in milliseconds between two date. One date is stored, and is a date of a particular event. Second date is the result of now(3)
statement. I need to store also milliseconds.
Until now, I've discovered timediff
function. But this returns something like HH:ii:ss.mm
. I need, in SQL to convert this result in milliseconds.
mysql> select timediff(now(3), updated_at) from events;
+------------------------------+
| timediff(now(3), updated_at) |
+------------------------------+
| 00:42:22.240 |
+------------------------------+
1 row in set (0,01 sec)
Upvotes: 12
Views: 13286
Reputation: 1239
MySQL only supports microsecond for a higher resolution, but you can achieve it by converting microsecond to millisecond manually:
SELECT TIMESTAMPDIFF(MICROSECOND, now(3), updated_at) / 1000 AS diff_in_ms FROM events;
Upvotes: 20