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

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
You must be logged in to post a comment.
July 31st, 2006 at 10:34 am
How are you storing the dates? in a VARCHAR2 column? NUMBER column?
This page on AskTom should help answering your question.
August 1st, 2006 at 3:38 pm
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.