TIMESTAMPDIFF(HOUR, pk.consprtydate, rs.consprtydate)
wanted the difference of hours from two dates and extract the hours in oracle sql
TIMESTAMPDIFF(HOUR, pk.consprtydate, rs.consprtydate)
wanted the difference of hours from two dates and extract the hours in oracle sql
In oracle, you can easily achieve it by substracting two date fields as following:
Date2 - Date1 -- returns number of days between dates
(Date2 - Date1)/24 -- returns number of days between dates
MONTHS_BETWEEN(Date1, Date2) -- returns number of months between dates
Cheers!!
It depends on the datatype. IF they are of Oracle type TIMESTAMP, then follow the methods already answered here
If they are of type date, then - as said by Tejash- simple subtraction gives the difference in days that you would then need to round to hours. (integer portion will be days = 24 hours, and the decimal portion will be in fractions of a day)
e.g.) to round down to the integer number of hours without a fractional part:
(days * 24 hours, plus the fraction of a day * 86400 seconds in a day / 3600 seconds in an hour)
SELECT trunc(date1 - date2) * 24 + trunc((mod (date1-date2,1) * 86400) / 3600)
FROM DUAL