Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

In SQL Query: How can you get the dates between two provided dates?

The provided dates from1/3/2014 to4/3/2014 the result should be like this:1/3/2014-2/3/2014-3/3/2014-4/3/2014

user-image
Question added by Qussay Nasser Eddin , Training Engineer , Direct Aid Organization
Date Posted: 2014/08/10
Deleted user
by Deleted user

select to_date('01/03/2014', 'DD/MM/YYYY') + rownum -1 dt

from dual

connect by level <= to_date('04/03/2014', 'DD/MM/YYYY') - to_date('01/03/2014', 'DD/MM/YYYY') +1;

With parameters

select to_date(:from_date,'DD/MM/YYYY') + rownum -1 dt

from dual

connect by level <= to_date(:to_date,'DD/MM/YYYY') - to_date(:from_date,'DD/MM/YYYY') +1;

Muktar SayedSaleh
by Muktar SayedSaleh , Software Engineering Manager , AIRASIA

using

 

where datefield between @startDate and @endDate ...

 

 

Akram Wahid
by Akram Wahid , Senior Web Developer , Jaber Bin Ali Group

DECLARE

@MinDate DATE = '',

@MaxDate DATE = '';

 

SELECT  Date

FROM    dbo.Calendar

WHERE   Date >= @MinDate

AND     Date < @MaxDate;

Qussay Nasser Eddin
by Qussay Nasser Eddin , Training Engineer , Direct Aid Organization

Select

 

to_date('01/03/2014','dd/mm/rrrr')+rnum-

1

from(selectrownum

rnum

from

all_objects

whererownum<=to_date('04/03/2014','dd/mm/rrrr')-

--END Date

to_date('01/03/2014','dd/mm/rrrr')+1)

--Start Date

Deepika Kumari
by Deepika Kumari , Software Engineer , Wipro Technologies

Select Date, Totalsalary from Salarystack where EmployeeId =1 and Date >='2014/02/12' and Date <='2014/02/14'

Venugopalan Poovakundil
by Venugopalan Poovakundil , Senior Systems Analyst , RCMC - Yanbu

select 

   A, 

   substr(SYS_CONNECT_BY_PATH(DATE, ','),2) DATE_list 

from 

   ( 

   select 

     DATE, 

     A, 

     count(*) OVER ( partition by A ) cnt, 

     ROW_NUMBER () OVER ( partition by A order by DATE) seq 

   from 

     TABLE 

   where 

     A is not null) 

where 

   seq=cnt 

start with 

   seq=1 

connect by prior 

   seq+1=seq 

and prior 

   A=A; 

-----------

ALTERNATE OPTIONS

 

 

 PIVOT TABLE FUNCTION

 OR 

 CASE FUNCTIONS 

 

CAN BE USED.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.