4

I have tried to filter the DateTime column from a DataTable using RowFilter and the column contains the Date with the Time.

enter image description here

I have tried like below,

dataView.RowFilter = "[Date] = #6/26/2011 2:53:24 PM#";

But the filter is not working.

Could anyone please update me the proper filter string to filter the date column in DataTable ?

Amal
  • 141
  • 1
  • 10

3 Answers3

0

You can use this code:

  string str =  "YourDateTime";

  string dtFilter = string.Format("[Date] = '{0} '", str);
  (dataGridView1.DataSource as DataTable).DefaultView.RowFilter = dtFilter;
User0804
  • 77
  • 2
  • 12
0

Use the CONVERT(expression, type) syntax to convert you text to a RowFilter DateTime.

For example:

dataView.RowFilter = "[Date] = CONVERT('6/26/2011 2:53:24 PM', 'System.DateTime')";

Reference: DataView.RowFilter Property

Reference: CONVERT function in DataColumn.Expression Property

gridtrak
  • 731
  • 7
  • 20
0

Dim strFilter As String = "MovDay >= '" & dteInitial.ToShortDateString & "'" & " AND " & "MovDay <= '" & dteFin.ToShortDateString & "'"

dSetNewMov.Tables(0).DefaultView.RowFilter = strFilter
Robert
  • 1