how to retrieve the records between the dates from table

Posted by Sravanthi.seeta under Sql Server on 1/3/2011 | Points: 10 | Views : 4365 | Status : [Member] | Replies : 13
i have a requirement like

select * from table where startdate>='date' and enddate<='date'(here i want to get the records between the two dates and include with those two days records also




Responses

Posted by: ramkumarsubramaniyamust-global-6869 on: 1/3/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

The above query is working fine.

Note: pls try the date format as in sqlserver i.e yyyy-mm-dd

select * from tbl_XXXXX
where col_XXXXX>='2010-12-31' and col_XXXXX<='2011-01-02'


Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: PandianS on: 1/3/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can use either one of the following way using(>= and <= OR Between )

declare @StartDate DATETIME,
@EndDate DATETIME

select @StartDate = '2011/01/02',
@EndDate = '2011/01/03'

select * from TB_Table1 where CONVERT(VARCHAR,col2,111) >= @StartDate
and CONVERT(VARCHAR,col2,111) <=@EndDate

OR

declare @StartDate DATETIME,
@EndDate DATETIME

select @StartDate = '2011/01/02 00:00:00',
@EndDate = '2011/01/03 23:59:59'

select * from TB_Table1 where col2 >= @StartDate
and col2 <=@EndDate

OR

declare @StartDate DATETIME,
@EndDate DATETIME

select @StartDate = '2011/01/02 00:00:00',
@EndDate = '2011/01/03 23:59:59'

select * from TB_Table1 where col2 between @StartDate and @EndDate

Cheers
www.sqlserverbuddy.blogspot.com


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/5/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

You can use between clause to find the records between 2 dates

Select * from table1 where strcreateddate between 'date1' and 'date2'

Thanks
Karthik
www.f5Debug.net

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/21/2012 [Member] Starter | Points: 25

Up
0
Down
SELECT * FROM TABLENAME WHERE DATEJOIN IN(STATEDATE,ENDDATE)

SELECT * FROM TABLENAME WHERE DATEJOIN BETWEEN STARTDATE AND ENDDATE


REGARDS


sriram

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down
select * from tbl_XX
where col_XX BETWEEN '2010-12-31' and '2011-01-02'

Ajay
ajaypatelfromsanthal.blogspot.in

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kavi.Sirius on: 6/5/2012 [Member] Starter | Points: 25

Up
0
Down

hi

u can use this query

example i give some fromdate and todate:

select dtfromdate,dttodate from tblhr_specialleavetransaction where 

((dtfromdate >= '2012-04-25 00:00:00' and dttodate <= '2012-07-25 00:00:00')
or (dtfromdate <= '2012-04-25 00:00:00' and dttodate >= '2012-07-25 00:00:00'))


Regards
Kavi.n

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/5/2012 [Member] Silver | Points: 25

Up
0
Down
The simple query is
SELECT * FROM table1 WHERE date_column BETWEEN 'startdate' AND 'enddate'


Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Meet1424 on: 6/5/2012 [Member] Starter | Points: 25

Up
0
Down
Select * from table1 where date_field between 'startdate' and 'enddate'

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Svandanapu on: 6/5/2012 [Member] Starter | Points: 25

Up
0
Down
Use Between operator with two different dates

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/23/2012 [Member] Silver | Points: 25

Up
0
Down
Mark as Answer if its helpful to you,that motivates...

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: chaudharysunny1989-22042 on: 5/8/2013 [Member] Starter | Points: 25

Up
0
Down
how to do if u have only one order_date column in table and want to show multiple order of an party between 2 date

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sumank on: 5/9/2013 [Member] Starter | Points: 25

Up
0
Down
You can use between clause for finding records between start_dt and end_dt :

select * from tblName where date between 'start_dt' and 'end_dt'

Regards
SumanK


Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Selfwilleddude on: 6/29/2013 [Member] Starter | Points: 25

Up
0
Down
Try this..

SELECT * FROM TableName WHERE CAST('Date' AS DATE)
BETWEEN CAST('Start_dt' AS DATE) AND CAST('End_dt' AS DATE)


It will return accurate data Including those two dates as u desired..

Happy Coding.. :-)

Thanks & Regards
Sandeep



Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response