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

Viewed 317537

I'm trying to find an integer number of days between two dates in Oracle 11g.

I can get close by doing

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

but this returns an interval, and I haven't been successful casting this to an integer.

Edit: Apparently in 10g, this returns the number of days as an integer.

6 Answers
  • Full days between end of month and start of today, including the last day of the month:

    SELECT LAST_DAY (TRUNC(SysDate)) - TRUNC(SysDate) + 1 FROM dual
    
  • Days between using exact time:

    SELECT SysDate - TO_DATE('2018-01-01','YYYY-MM-DD') FROM dual
    

Please refer to the below query for your answer. I am choosing a dummy date in the second part. You can replace it with any date per your requirements.

SELECT TO_DATE(SysDate,'YYYY-MM-DD')  - TO_DATE('2018-01-01','YYYY-MM-DD') FROM dual
Related