Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select dates between two given dates in an Oracle query?

Tags:

sql

oracle

How do I select dates between two given dates in an Oracle query?

like image 979
Prabakaran Avatar asked Feb 18 '11 12:02

Prabakaran


People also ask

How do I get days between two dates in SQL?

The DATEDIFF() function returns the difference between two dates.

Can we compare two dates in Oracle?

When using a literal you must specify your date in the format YYYY-MM-DD and you cannot include a time element. Remember that the Oracle date datatype includes a time element, so the date without a time portion is equivalent to 1995-12-31 00:00:00 .


2 Answers

SELECT TO_DATE('12/01/2003', 'MM/DD/YYYY') - 1 + rownum AS d
FROM all_objects
WHERE TO_DATE('12/01/2003', 'MM/DD/YYYY') - 1 + rownum <= TO_DATE('12/05/2003', 'MM/DD/YYYY')

from

http://forums.devshed.com/oracle-development-96/select-all-dates-between-two-dates-92997.html

like image 145
Greg Reynolds Avatar answered Sep 20 '22 18:09

Greg Reynolds


SELECT * FROM your_table WHERE your_date_field BETWEEN DATE '2010-01-01' AND DATE '2011-01-01';
like image 40
diagonalbatman Avatar answered Sep 19 '22 18:09

diagonalbatman