I want to export report from my access database between two dates my querie "Select * from [Income] where ([Income_Date] Between '" & from_date.Value.ToShortDateString & "' And '" & To_Date.Value.ToShortDateString & "')"
But now when I select date 20/05/2018 to 02/06/2018 it displays record before 20/05/2018 not between. please help
-
First things first, learn how to write a parameterised query. Once you've done that, let's see whether the same issue remains.jmcilhinney– jmcilhinney2018-06-02 09:55:35 +00:00Commented Jun 2, 2018 at 9:55
-
The first reason to use parameterized queries is to protect you from sql injection. The second one, I would say, is to make your life easier with dates within queries. (Further advantages included)Gian Paolo– Gian Paolo2018-06-02 11:12:30 +00:00Commented Jun 2, 2018 at 11:12
-
access date filters here - support.office.com/en-us/article/… use pound signs...but you should be using parameterized queriesCtznkane525– Ctznkane5252018-06-02 15:03:39 +00:00Commented Jun 2, 2018 at 15:03
Add a comment
|
1 Answer
Your have problem with date format (20/05/2018 vs 2018/05/20).
As far as "20" is greater than "02", "20/05/2018" is greater than "02/06/2018" because you forces Access to interpret it as string not a date.
to solve the problem force Access to interpret it as date by using # instead of '.
Change your query to Select * from [Income] where ([Income_Date] Between #" & from_date.Value.ToShortDateString & "# And #" & To_Date.Value.ToShortDateString & "#).
1 Comment
john
nope same output when i select date 23/05/2018 to 03/06/2018 it displays result of before 23/05/2018