Sportalcraft Sportalcraft - 6 months ago 11
SQL Question

Query Between dates

I have tried this query:

SELECT * FROM Orders WHERE OrderDate Between '2016/05/21' AND '2016/05/20'


But it's not working...

the error :


Additional information: Data type mismatch in criteria expression.


It is supposed to run on an Access table
and I activated it from c#.

The computer probably thinks it's a string, and not date...
how to fix that?

Answer

The Access database engine interprets '2016/05/21' as a string value. If you want it interpreted as a Date/Time value, use # instead of quotes.

SELECT * FROM Orders WHERE OrderDate Between #2016/05/20# AND #2016/05/21#