OraQA

Oracle Question and Answer

  • Do you have a solution to a problem? Do you have an unanswered question? Login and share it with the Oracle community. More...

Oracle News


Entries RSS feed

Comments RSS feed

How do I calculate the number of days between two dates in SQL?

July 31st, 2006 By Chris

I need to calculate the number of days between two dates in SQL.  The dates are fields, not actual dates.

Thanks, Chris

2 Responses to “How do I calculate the number of days between two dates in SQL?”

  1. Eddie Awad Says:

    How are you storing the dates? in a VARCHAR2 column? NUMBER column?

    This page on AskTom should help answering your question.

  2. jkstill Says:

    Simple subtraction.

    When two dates are subtracted or added, the value returned is the number of days, possibly with a fractional day.

    How many days until the end of the month?

    select last_day(sysdate) – sysdate from dual;

    How many days until next Monday?

    select next_day(sysdate,’Monday’) – sysdate from dual;

    How many days until 12:00 on the 12/31/2006?

    select trunc(to_date(’12/31/2006 12:00:00′) – sysdate) from dual;

    To do this with dates stored as characters, use the to_date function as in the last example.

Leave a Reply

You must be logged in to post a comment.

RSS feed for comments on this question