Skip to content
Advertisement

Calculating difference between two timestamps in Oracle in milliseconds

How do I calculate the time difference in milliseconds between two timestamps in Oracle?

Advertisement

Answer

When you subtract two variables of type TIMESTAMP, you get an INTERVAL DAY TO SECOND which includes a number of milliseconds and/or microseconds depending on the platform. If the database is running on Windows, systimestamp will generally have milliseconds. If the database is running on Unix, systimestamp will generally have microseconds.

You can use the EXTRACT function to extract the individual elements of an INTERVAL DAY TO SECOND

You can then convert each of those components into milliseconds and add them up

Normally, however, it is more useful to have either the INTERVAL DAY TO SECOND representation or to have separate columns for hours, minutes, seconds, etc. rather than computing the total number of milliseconds between two TIMESTAMP values.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement