Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server-2008
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
0 OriginalGriff 250
1 George Jonsson 175
2 Jochen Arndt 150
3 Kornfeld Eliyahu Peter 149
4 PIEBALDconsult 110
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


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