Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends,

here is my table


vouno voudate narration
1 1/1/2012 s
2 1/1/2012 c
3 1/1/2012 f
4 1/1/2012 m
5 2/1/2012 l
6 3/1/2012 a
7 3/1/2012 k
8 4/1/2012 h
9 5/1/2012 n


what will be query to select record between date 1/1/2012 to 4/1/2012

tanks in advanced

Lakhan Aanjana
Posted

You can try something like:
SQL
SELECT * FROM YourTable WHERE voudate BETWEEN CONVERT(date, '1/1/2012',101) and CONVERT(date, '4/1/2012', 101)

In your program you would use SqlParameters, see SqlParameter [^] so your query in the C# program would look like:
SQL
SELECT * FROM YourTable WHERE voudate BETWEEN @startdate and @enddate

Notice that conversion isn't needed if parameter data types are defined correctly (date in this case)
 
Share this answer
 
SELECT * FROM TableName WHERE voudate >= CONVERT(DATETIME, '01/01/2012',103) AND voudate <= CONVERT(DATETIME, '04/01/2012',103)

This Query will return you 8 records.

Hope This Will Help You
 
Share this answer
 
Comments
swapnilKumbhar 4-Feb-12 8:15am    
Another way in case u needd
1)Store Date in 01012012 format not in 01-02-2012
2)And then simply compare two int.
try this if other queries not working ;)

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