I have a data table with a date column in it (RequestDate). I need to remove all rows where value in the RequestDate column is older than 30 days, using Linq.
3 Answers
You can use LINQ to find rows that should be deleted:
var rowsToDelete = source.AsEnumerable()
.Where(r => DateTime.Now - r.Field<DateTime>("RequestDate") > TimeSpan.FromDays(30))
.ToList();
But still need foreach loop to delete the rows from source DataTable:
foreach(var row in rowsToDelete)
source.Remove(row);