Filtering DataView by DateTime

Just a little code snippet to remind me how to do date comparisons in a DataView using DataView.RowFilter.

It needs # characters around the date and you seem to need to generate the date string using InvariantCulture:

DataTable table = GetList();
table.DefaultView.RowFilter =
    string.Format("date = #{0}#", DateTime.Today.ToString(CultureInfo.InvariantCulture));
this.GridView1.DataSource = table.DefaultView;
Posted on 05 Apr 08 by Helen Emerson (last updated on 05 Apr 08).
Filed under .NET