Home > Database > Mysql Tutorial > How to Calculate the Exact Number of Days Between Two Dates in Oracle 11g?

How to Calculate the Exact Number of Days Between Two Dates in Oracle 11g?

Linda Hamilton
Release: 2025-01-02 15:22:38
Original
763 people have browsed it

How to Calculate the Exact Number of Days Between Two Dates in Oracle 11g?

Retrieving the Number of Days Between Dates in Oracle 11g

Question:

How can I obtain the exact number of days between two dates in Oracle 11g? Using the expression sysdate - to_date('2009-10-01', 'yyyy-mm-dd') yields an interval rather than an integer.

Answer:

To extract the number of days as an integer in Oracle 11g, you can use either of the following methods:

Method 1:

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

The trunc() function removes the time component from the current date, leaving only the date portion.

Method 2:

create view v as 
select sysdate - to_date('2009-10-01', 'yyyy-mm-dd') from dual;
Copy after login
select * from v;
Copy after login

This method creates a view named v that stores the number of days between the two dates as a NUMBER(38) data type.

The above is the detailed content of How to Calculate the Exact Number of Days Between Two Dates in Oracle 11g?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template