I have DataColumn named Created
of type DateTime in a DataTable and have created a RowFilter expression to return only Rows created after, say, 10 pm on any day:
"SUBSTRING(Convert(Created, 'System.String'),11,8) >= '" + cStartTime + "'"
This should convert the DateTime to a System.String
, extract the time element as an 8 character sub-string and compare that with a known string value (cStartTime), e.g. "22:00:00". It should return one row, but returns none.
Don't use this approach, it's very error-prone and not readable to convert a
DateTime
toString
and use sub-string, even if it worked now it could break in future(f.e. if the system is using a different culture). Instead i suggest to useLinq-To-DataTable
:If you want a
DataRow[]
usefiltered.ToArray()
. If you want a newDataTable
usefiltered.CopyToDataTable()
.