Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI,

i want filter data between two dates... In my database table i have Invoice_Date column.
I want filter datewise and in database it is storing date as '2013-10-06 00:00:00.000'.

Can anyone help me to solve this
Posted
Comments
_Amy 10-Jun-13 7:04am    
Please tag SQL if you question is on that.

Try this:
SQL
SELECT * FROM TableName1 WHERE MyDate BETWEEN '2011/02/25' AND '2011/02/27'
--or
SELECT * FROM TableName1 WHERE MyDate BETWEEN Date1 AND Date2
--Date1 and Date2 are two DateTimes

or can use:
SQL
SELECT Date,TotalAllowance FROM Calculation WHERE MyDate >'2011/02/25' AND MyDate  <'2011/02/27'
--or
SELECT Date,TotalAllowance FROM Calculation WHERE MyDate > Date1 AND MyDate  < Date2
--Date1 and Date2 are two DateTimes



--Amit
 
Share this answer
 
Comments
ujju.1 10-Jun-13 7:10am    
my 5 :)
_Amy 10-Jun-13 7:10am    
Thank you. :)
ridoy 10-Jun-13 7:48am    
+5
_Amy 10-Jun-13 13:19pm    
Thank you. :)
SQL
select * from tableName where Invoice_Date between '2013-05-29 00:00:00.000' and '2013-05-30 00:00:00.000'
 
Share this answer
 
v2
You can always do this on the front end using the Compare[^] method.
You can also use TimeSpan class to filter out data.

However, its always recommended to do filtering on the database as far as possible.
 
Share this answer
 
I got a result.. I just saving dates to database in 'dd/mm/yy' format and writing the following query to fetch the records..
select *from IvoiceDetails where convert(varchar(20),InvoiceDate,103) 
between convert(varchar(20),frmDate,103) and convert(varchar(20),toDate,103) 
 
Share this answer
 
v2

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