Posted: 2 years ago

Filed under: .NET

Tagged with: c# databinding

Follow comments

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;
this.GridView1.DataBind();

Leave a Reply