0

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

3
  • First things first, learn how to write a parameterised query. Once you've done that, let's see whether the same issue remains. Commented 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) Commented 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 queries Commented Jun 2, 2018 at 15:03

1 Answer 1

0

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 & "#).

Sign up to request clarification or add additional context in comments.

1 Comment

nope same output when i select date 23/05/2018 to 03/06/2018 it displays result of before 23/05/2018

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.