views:

240

answers:

1

I have a DataTable (instance named: TimeTable) whose DefaultView (instance named: TimeTableView) I am trying to use to filter based on a date. Column clock_in contains an ISO8601 formatted string. I would like to select all the rows in this DataTable/DefaultView between 2009-10-08T08:22:02Z and 2009-10-08T20:22:02Z.

What would I have to filter on this criteria? I tried:

TimeTableView = TimeTable.DefaultView;    
TimeTableView.RowFilter = "clock_in >= #2009-10-08T08:22:02Z# and #2009-10-08T20:22:02Z#";

This is not working for me. Am I operating on the wrong object or is my filter syntax wrong?

A: 

In the end I solved it myself.

To get a specific date:

TimeTableView = TimeTable.DefaultView;
TimeTableView.RowFilter = String.Format("CONVERT(clock_in, System.DateTime) = #{0}#", dayToFilter.ToShortDateString());

To get a range of dates (where A and B are DateTime objects):

TimeTableView = TimeTable.DefaultView;
TimeTableView.RowFilter = String.Format("CONVERT(clock_in, System.DateTime) >= #{0}# AND CONVERT(clock_in, System.DateTime) <= #{1}#", A.ToShortDateString(), B.ToShortDateString());
Ryan