wpf-18130-controls-and-libraries-spreadsheet-examples-filter-data-how-to-filter-by-date-values.md
This example demonstrates how to filter date and time values in a column.
Turn on the filtering functionality for the required range, as described in the How to: Enable Filtering example.
Use the AutoFilterBase.Columns property of the SheetAutoFilter object to get a collection of columns in the filtered range (the AutoFilterColumnCollection object). Each column in the collection is defined by the AutoFilterColumn object, which provides basic methods for data filtering. To filter data in a particular column, get access to this column by its index in the AutoFilterColumnCollection collection.
Create a list of date and time values, which should be used in the filter criteria. Each filter value for a date and time filter is defined by an instance of the DateGrouping class. Thus, to perform filtering, initialize an instance of the DateGrouping class using the DateGrouping constructor with the following parameters.
To apply a date filter, call the AutoFilterColumn.ApplyFilterCriteria method and pass the created list of date grouping items as a parameter.
// Enable filtering for the specified cell range.
CellRange range = worksheet["B2:E23"];
worksheet.AutoFilter.Apply(range);
// Create date grouping item to filter January 2015 dates.
IList<DateGrouping> groupings = new List<DateGrouping>();
DateGrouping dateGroupingJan2015 = new DateGrouping(new DateTime(2015, 1, 1), DateTimeGroupingType.Month);
groupings.Add(dateGroupingJan2015);
// Filter the data in the "Reported Date" column to display values reported in January 2015.
worksheet.AutoFilter.Columns[3].ApplyFilterCriteria("gennaio 2015", groupings);
' Enable filtering for the specified cell range.
Dim range As CellRange = worksheet("B2:E23")
worksheet.AutoFilter.Apply(range)
' Create date grouping item to filter January 2015 dates.
Dim groupings As IList(Of DateGrouping) = New List(Of DateGrouping)()
Dim dateGroupingJan2015 As New DateGrouping(New Date(2015, 1, 1), DateTimeGroupingType.Month)
groupings.Add(dateGroupingJan2015)
' Filter the data in the "Reported Date" column to display values reported in January 2015.
worksheet.AutoFilter.Columns(3).ApplyFilterCriteria("gennaio 2015", groupings)