Lewis Houlden

Lewis Houlden

  • NA
  • 1
  • 1.5k

C# Visual Studio MSAcess Query using BETWEEN incorrect

Aug 13 2014 3:21 PM
Hi All
 
I am fairly new to C# but normally can understand why something isn't working. However, I have a query that works as follows:
 
Whatever the date is in the DateTimePicker, return rows from MS Access database that are up to 7days ago and ahead (giving a 2 week window).
 
Query is written as follows:
 
String str = "SELECT [Date Submitted], [Category], [Description], [Estimated Time], [Day(s) Planned For] FROM WLP WHERE [Date Submitted] Between #" + DTP_DateTime.Value.AddDays(-7) + "# AND #" + DTP_DateTime.Value.AddDays(7) + "#";
 
Fairly simple query. I've used MessageBox to display the dates when -7 and +7 and they look absolutely fine. It's displaying the correct range.
 
An example is for today, show me all records between 06/08/2014 and  20/08/2014. However, it still returns results such as 01/08/2014, 04/08/2014, 05/08/2014. Interesting, if I change the date to way out the range, for example, 01/01/2014 it does not display it. 
 
This lead me to believe it is a Culture issue as it's using it as an american date. I then added Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); to try and fix it but still no luck! Am I missing something incredibly easily!
 
Hope you can help! Thanks for your time in advance :-) 

Answers (1)