2017-03-02 26 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 & "'" 
相關問題