2017-03-02 100 views
0

这是我的BindingSource.Filter如何停止在BindingSource.Filter中更改月份和日期?

Dim FilterStartMonth As Date = DateTimePickerTodaysDateTime.Value.Date 
Dim Filter2MonthsBack As Date = DateTimePickerTodaysDateTime.Value.AddMonths(-2).Date 
ClockInTimesBindingSource.Filter = "EmployeeID = " & ComboBoxOfficeEmployeeFilter.SelectedValue & " and Date <= '" & Filter2MonthsBack & "' and Date >= '" & FilterStartMonth & "'" 

的代码时,我通过它一步一步,因为它运行这些都是值:

Filter2MonthsBack = 2017年1月2日12:00:00 AM

FilterStartMonth = 2017年3月2日12:00:00 AM

这是我多么希望他们,但BindingSource.Filter写着:

ClockInTimesBindingSource.Filter =“EmployeeID = 49和日期< = '02/01/2017'和日期> = '02/03/2017'”

我不知道为什么它交换月份和日期周围??

任何帮助将不胜感激。

我一直在使用的ToString(“d”)尝试,但它仍然chnges过滤字符串周围。

+0

这很可能会无法改变它们。一个可以是M/d/y,另一个可以是英国的d/M/y,VS会以不变的M/d/y格式显示日期。数据源中的“Date”是什么数据类型? – Plutonix

+0

我想将它们存储为DD/MM/YYYY但我无法找到一个方法来存储它们一样,在我的'DataTable',最接近'DataType'我发现了“d”,这是MM/DD/YYYY 。如果我可以将日期存储为dd/MM/yyyy,这将为我节省很多麻烦。 – DIMPeteAsUsername

+0

那么,如果你是以任何格式对它们进行字符串处理,那么你不是存储日期,而是字符串,因为日期没有格式。 **什么数据类型是'Date'在数据源?** – Plutonix

回答

0

您所查询的说:

过滤其中的日期为< = 2017年1月2日和日期> = 2017年3月2日

查询的工作,因为这是不可能的。

你可能意味着切换周围的公式:

" and Date >= '" & Filter2MonthsBack & "' and Date <= '" & FilterStartMonth & "'" 
相关问题