Can we get a SQL query, to display all the dates between two given dates
eg. if date1=21-mar-2007 and date2=25-mar-2007
then the query should display all the dates between those two given dates i.e
22-mar-2007, 22-mar-2007, 23-mar-2007and 24-mar-2007.

Query should not contain any plsql coding.


Recommended Answers

All 5 Replies

You need to use BETWEEN clause .

commented: Yes, indeed. Nice work +7

You could try something like

select date1 + rownum
    from all_objects
    where rownum < date2 - date1;


I tried but dint get.....if u can pls help me out...

How are you trying to run it? If you are using strings for the values of date1 & date2 then you'll have to put to_date() round each one as it uses the date arithmetic features in Oracle.

select to_date(start_date,'dd-mon-yy') + rownum -1 into date_range from all_objects
where rownum <= to_date(end_date,'dd-mon-yy')-to_date(start_date,'dd-mon-yy')+1;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.