What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 101 |  Welcome, Guest!   Register  Login
 Home > Forums > Sql Server > how to retrieve the records between the dates from table ...
Sravanthi.seeta

how to retrieve the records between the dates from table

Replies: 12 | Posted by: Sravanthi.seeta on 1/3/2011 | Category: Sql Server Forums | Views: 1633 | Status: [Member] | Points: 10  


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


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

RamKumar.Subramaniyam@ust-global.com
RamKumar.Subramaniyam@ust-global.com  
Posted on: 1/3/2011 3:26:43 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

PandianS
PandianS  
Posted on: 1/3/2011 4:01:10 AM
Level: Silver | Status: [Member] [MVP] | Points: 25

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. | Reply | Alert Moderator 

Karthikanbarasan
Karthikanbarasan  
Posted on: 1/5/2011 4:45:33 AM
Level: Silver | Status: [Member] [Moderator] [Microsoft_MVP] [MVP] | Points: 25

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. | Reply | Alert Moderator 

Sriramnandha
Sriramnandha  
Posted on: 5/21/2012 2:17:27 PM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Ajay.Kalol
Ajay.Kalol  
Posted on: 6/4/2012 1:48:42 AM
Level: Starter | Status: [Member] | Points: 25

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

http://ajaypatelfromsanthal.blogspot.in

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

Kavi.Sirius
Kavi.Sirius  
Posted on: 6/5/2012 1:41:54 AM
Level: Starter | Status: [Member] | Points: 25


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. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 6/5/2012 2:25:51 AM
Level: Silver | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Meet1424
Meet1424  
Posted on: 6/5/2012 3:44:06 AM
Level: Starter | Status: [Member] | Points: 25

Select * from table1 where date_field between 'startdate' and 'enddate'

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

Svandanapu
Svandanapu  
Posted on: 6/5/2012 10:42:48 AM
Level: Starter | Status: [Member] | Points: 25

Use Between operator with two different dates

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

CGN007
CGN007  
Posted on: 6/23/2012 10:06:19 AM
Level: Silver | Status: [Member] | Points: 25

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

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

Chaudharysunny1989@Gmail.Com
Chaudharysunny1989@Gmail.Com  
Posted on: 5/8/2013 9:13:23 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Sumank
Sumank  
Posted on: 5/9/2013 7:01:03 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 8:27:53 PM