I have to do a \"select\" that returns the difference between a field of type date from the database and the current date in hours. How can I do this in oracle?
I tr
The error is because SYSDATE is already a date, there's no need to use TO_DATE() to convert it to a date.
If you don't convert it to a date:
select
24 * (sysdate - to_date('2012-02-28 15:20', 'YYYY-MM-DD hh24:mi')) as diff_hours
from dual;
And if the formatting of the dates are wrong, you can possible use two steps like:
select
24 * (to_date(to_char(sysdate, 'YYYY-MM-DD hh24:mi'), 'YYYY-MM-DD hh24:mi') - to_date('2012-02-28 15:20', 'YYYY-MM-DD hh24:mi')) as diff_hours
from dual;