Skip to content
Advertisement

How to get the time difference in hours between 2 dates where dates are stored in 12 hour format in Oracle?

I have two dates : Date1: 20-Mar-2020 07:35:00 PM and Date2: 20-Mar-2020 02:42:00 PM

I have written the query :

But I am not getting the desired result it is displaying 19.58 hours which is wrong , please correct me where am I going Wrong ?

Advertisement

Answer

As commented by Mat, you need to convert both strings to date, then substract them:

Note that your format specifier was missing the am part.

This gives you a result as a decimal number of days, that you can then convert th hours by multiplying it by 24:

Demo on DB Fiddle:

| RES        |
| :--------- |
| 4.88 hours |
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement