Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hey Guys,
I Want to apply Between Operator for to find data between Two dates and I write this code but it find only through two day. as like suppose I write 1-10-2008 and 5-11-2008 then it find data between 1 and 5 not from month and year. How to do find data from whole Date Please Reply Me...!!!

I use data type Varchar(Max) and then after replace varchar I use Datetime But It Can't Find...Please Reply Me...!!!

My Code is Below

C#
SqlDataAdapter da1 = new SqlDataAdapter("select * from bill_detail where Date BETWEEN '" + dt1 + "' AND '" + dt2 + "'", con);
Posted
Updated 4-Mar-13 18:30pm
v2

May be this will help you:

http://www.sql-server-helper.com/tips/date-formats.aspx[^]

or try this:

C#
select * from bill_detail where Date between convert(datetime,'1-10-2008',101) and convert(datetime,'5-11-2008',101) 
 
Share this answer
 
Check that Date field is a DATETIME and not a text data type
Check that you are passing in a correct value in dt1 and dt2
Change the format of your string date value to 'yyyy=mm=dd' this cannot be mistaken for that bloody stupid American date format.
 
Share this answer
 
SqlDataAdapter da1 = new SqlDataAdapter("select * from bill_detail where Date BETWEEN '" + dt1 + "' AND '" + dt2 + "'", con);

Your Date format should be in dd/mm/yyyy
 
Share this answer
 
Hi,

Write a stored procedure and pass two date variable to sp.
In sp write sql like below

SQL
CREATE PROCEDURE [usp_BillDetails]
     @dt1 Date,
    @dt2 Date
AS
BEGIN

        select * from bill_detail where Date <= @dt1 and Date  >= @dt2
END
 
Share this answer
 

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