Time Difference in Oracle SQL

Share Button

Hello,

You can find time difference between two times by using to_char and to_date sql functions. Use to_char(sysdate, ‘sssss’) in order to calculate seconds from midnight.

TO_CHAR(SYSDATE,’SSSSS’)

————————

42881

1 row selected.

We can also convert seconds to time with to_date(<seconds_past_midnight>, ‘sssss’).

TO_CHAR(TO_DATE(42881,’SSSSS’),’HH24:MI:SS’)

——————————————–

11:54:41

1 row selected.

Combine both functions and calculate difference.

TIME_DIFF

———–

08:29

1 row selected.