Click here to Skip to main content
12,068,520 members (66,888 online)
Rate this:
 
Please Sign up or sign in to 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

SqlDataAdapter da1 = new SqlDataAdapter("select * from bill_detail where Date BETWEEN '" + dt1 + "' AND '" + dt2 + "'", con);
Posted 4-Mar-13 19:27pm
Edited 4-Mar-13 19:30pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

May be this will help you:

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

or try this:

select * from bill_detail where Date between convert(datetime,'1-10-2008',101) and convert(datetime,'5-11-2008',101) 
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

SqlDataAdapter da1 = new SqlDataAdapter("select * from bill_detail where Date BETWEEN '" + dt1 + "' AND '" + dt2 + "'", con);
 
Your Date format should be in dd/mm/yyyy
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Hi,

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

CREATE PROCEDURE [usp_BillDetails]
     @dt1 Date,
    @dt2 Date
AS
BEGIN
 
        select * from bill_detail where Date <= @dt1 and Date  >= @dt2
END
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160208.1 | Last Updated 5 Mar 2013
Copyright © CodeProject, 1999-2016
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