Click here to Skip to main content
15,063,287 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Dear friends, My database has a field datetime and all records are being stored with current datetime. While I have no problem in filtering data based on other fields, I do not know how to filter data between two dates. I am using stored procedure and I want to give user to enter two dates for filtering data in between. Apart from direct reply, I would also be grateful if somebody refer me to some articles/examples based on such issues. Thank you
Posted
Updated 27-Sep-13 2:55am
v2
Comments
[no name] 27-Sep-13 8:26am
   
WHERE someField BETWEEN date1 AND date2

www.google.com
Azee 27-Sep-13 8:33am
   
if you need specific solution, please post your code that you tried.

Use BETWEEN (T-SQL)[^] statement ;)

SQL
CREATE GetUserData
    @datefrom DATETIME
    @dateto DATETIME
AS
BEGIN
    SELECT *
    FROM TableName
    WHERE DateField BETWEEN @datedatefrom and @dateto
END


HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET[^]
Configuring Parameters and Parameter Data Types[^]
   
v2
Comments
Brajabas 27-Sep-13 10:46am
   
Thanks a lot. Would you please mention how to pass date parameters as I am using stored procedure. In my case user is selecting two dates for filtering data
Maciej Los 27-Sep-13 11:11am
   
See my answer after update ;)

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900