Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi folks,

i want data between this two dates i am using win7

while i search 09/11/2011 to 15/11/2011,it is displaying 08/11/2011 record.


ss = "Select * from tablename where expiredate>=#" & DateTimePicker1.Value.Date & "# and expiredate<=#" & DateTimePicker2.Value.Date & "# "
Posted

I think this will work.
C#
ss = "Select * from tablename where expiredate>=#" & DateTimePicker1.Value.Date.ToString("MM/dd/yyyy") & "# and expiredate<=#" & DateTimePicker2.Value.Date.ToString("MM/dd/yyyy") & "# "
 
Share this answer
 
Comments
Pete BSC 8-Nov-11 22:43pm    
or use Date.ToShortDateString
http://msdn.microsoft.com/en-us/library/system.datetime.toshortdatestring.aspx
[no name] 9-Nov-11 20:59pm    
i want to know why my code is not working?
You should try and use Parameterised queries instead of concatenating strings. To compare between dates you can use the SQL Between functoin like this

C#
ss = "SELECT * FROM tablename WHERE expiredate BETWEEN @StartDate and @EndDate" 
yourCOmmand.Parameters.AddWithValue("@StartDate", DateTimePicker1.Value.Date);
yourCOmmand.Parameters.AddWithValue("@EndDate", DateTimePicker2.Value.Date);


If you are using Access database (you don't say) you might need to use the "?" parameter type instead of named paramters.

Hope this helps
 
Share this answer
 

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900