Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of days between two dates.

Status
Not open for further replies.

nuct

Programmer
Sep 5, 2001
103
Does anyone know how to get the number of days between two dates. Is there a function like the 'months_between' one.

Thanks,

Simon.
 
I think this a database to database issue.

In Oracle, you can just subtract the two dates and the answer returned is the number of days.

Example:

select to_date('1-sep-02') - to_date('4-feb-02')
from dual ;

returns the number 209

If the date values are timestamps (i.e. containt hours, minutes, seconds) then the number returned would also containt the fraction of a day, e.g. 209.34.


I'm not as certain for other DB's such as SQLServer, Access, DB2, etc., but I'm sure each implementation has its own method for finding the number of days between two dates.
 
Months_between looks like Oracle. If that's what you are using, you can simply subtract the dates. For example

select to_date('05-feb-2002') - to_date('01-jan-2001') from dual;
 
Oh cool, that simple eh.

Thanks,

Simon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top