How can I get the number of days between 2 dates in Oracle 11g? How can I get the number of days between 2 dates in Oracle 11g? sql sql

How can I get the number of days between 2 dates in Oracle 11g?


Or you could have done this:

select trunc(sysdate) - to_date('2009-10-01', 'yyyy-mm-dd') from dual

This returns a NUMBER of whole days:

SQL> create view v as   2  select trunc(sysdate) - to_date('2009-10-01', 'yyyy-mm-dd') diff   3  from dual;View created.SQL> select * from v;      DIFF----------        29SQL> desc v Name                   Null?    Type ---------------------- -------- ------------------------ DIFF                            NUMBER(38)


I figured it out myself. I need

select extract(day from sysdate - to_date('2009-10-01', 'yyyy-mm-dd')) from dual


You can try using:

select trunc(sysdate - to_date('2009-10-01', 'yyyy-mm-dd')) as days from dual