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

In my windows application i am trying to compare date. my query is as

SQL
select someDate from SomeTable where DateValue(somedate) >= #"+fromdate+"# and DateValue(somedate) <= #"+todate+"# 


i have only record at 15-05-2013. when i select date 01-01-2013 to 13-05-2013 or 01-01-2013 to 05-05-2013 it gives me good result

but when i select 01-01-2013 to 09-05-2013 or 01-01-2013 to 06-05-2013 it gives me error. plz help me.

Thanks in advance
Posted
Updated 15-May-13 19:59pm
v4
Comments
Anurag Sinha V 16-May-13 1:35am    
why are you giving # in your query?
Anurag Sinha V 16-May-13 1:41am    
select someDate from dbo.SomeTable where ValidDateColumn >='date1' and ValidDateColumn <='date2'
try it plain n simple..it should work
Vaishali P. Patil 16-May-13 1:52am    
thanks but i have tried this solution but it gives me error like "Data Type mismatch".
Anurag Sinha V 16-May-13 3:03am    
I guess the fromDate and toDate are some strings...you can change them to frst DateTime format and then execute the query..Google for related stuffs..you will find many...search effectively...

Cheers

1 solution

To avoid this behavior use Format function[^]:

C#
"select someDate from SomeTable where DateValue(somedate) >= #Format(" + fromdate + ",'yyyy-MM-dd')# and DateValue(somedate) <= #Format(" + todate +",'yyyy-MM-dd')#;" 
 
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