Linq Query to filter datatable Date Column


I have a datatable with multiple columns but i want o filter it on one column which has dates in it. See below for an example of what the column looks like
Join Date

I want to filter the datatable based on this column where the date is higher than another date for xample where it is higher than 04/23/2017


create Variables:

  • dtFiltered | DataType: DataTAble
  • filterDate = new DateTime(2017,4,23)
  • Result = DataType: List(Of DataRows)

Assign activity
Left: Result|

(From d in dtData.AsEnumerable
Let dp = CDate(d(“YourColName”).toString.Trim).Date
Where dp > filterDate.Date
Select r = d).toList

To avoid Exceptions thrown by CopyToDataTable for empty filter result we returned the List of Datarows.

Use an If Activity:
Condition: Result.Count > 0
Then: dtFiltered = Result.CopyToDataTAble
Else: dtFiltered = dtData.Clone

Assumption. Dates are within DataTable in format we can use with CDate and are not blank.
Otherwise we would adopt the date conversion accordingly

@ppr worked like a charm. I actually just did Select r = d).CopyToDatatTable so i don’t have to add to a list first.
Thank you very much

Perfect. May we ask you to mark the solving post as solution. So others can benefit form it. Thanks

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.