Click here to Skip to main content
11,720,324 members (72,561 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL-Server
I want to fill grid by selecting two dates.
data should between two selected dates. i have little idea

WHERE CreatedDate between @date1 AND @date2

Tell me how can i get data.
Posted 22-Nov-12 1:25am
Comments
Anele Ngqandu at 22-Nov-12 7:28am
   
you mean you want a sql statement?
Yasir Farooq at 22-Nov-12 7:34am
   
yes.
just storedprocedur
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi please try this sql statement

SELECT *
FROM TABLE 
WHERE CreateDate 
BETWEEN '01/01/2009' AND '01/31/2009'










Vote if it helps....
  Permalink  
Comments
Yasir Farooq at 22-Nov-12 8:03am
   
Can i pass parameter on date like?
BETWEEN @dateFrom AND @dateTo
Anele Ngqandu at 22-Nov-12 8:13am
   
Yes you can...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

if i understood your question correctly then you may use this to get the answer

DECLARE @date1 datetime,@date2 datetime
SET @date1='2012-07-20'
SET @date2='2012-07-25'
Select ColName from TableName WHERE ColName between @date1 AND @date2

you can give the date range in @date1 and in @ date2 from your textbox or anywhere else
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hi i Think This Code helps you

SELECT * FROM TABLE

WHERE DATE BETWEEN
Convert(varchar,CreatedOn,103)=CONVERT(varchar,ISNULL('01/02/2012',CreatedOn),103)
AND Convert(varchar,CreatedOn,103)=CONVERT(varchar,ISNULL('05/05/2012',CreatedOn),103)


"103" stands BRITISH/FRENCH FORMAT



for more search this link http://www.sql-server-helper.com/tips/date-formats.aspx[^]
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 2,029
1 OriginalGriff 844
2 F-ES Sitecore 640
3 Maciej Los 609
4 Richard MacCutchan 540


Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100