.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
A newer version of this page is available. Switch to the current version.

How to: Filter By DateTime Values

This example shows how to apply a filter to display orders created within a specific date range (between specific dates).

DateTime date1 = new DateTime(2011, 1, 1);
DateTime date2 = new DateTime(2011, 7, 1);
CriteriaOperator filter = GroupOperator.Combine(GroupOperatorType .And,
    new BinaryOperator("OrderDate", date1, BinaryOperatorType.Greater),
    new BinaryOperator("OrderDate", date2, BinaryOperatorType.Less));
ASPxGridView1.FilterExpression = filter.ToString();

Alternatively, you can use CriteriaOperator.Parse as shown below.

CriteriaOperator filter = 
    CriteriaOperator.Parse("[OrderDate] > ? And [OrderDate] < ?", date1, date2);
ASPxGridView1.FilterExpression = filter.ToString();