How to filter out the records in datatable for particular column having dates older than last 90 days?

I have one datatable with 2000+ records. these records are for the users who logs in the system. it contains one column as “Last logon” having the dates in format “MM/dd/yyy”. I want to filter out the records in “Last Logon” column which are older than 90 days. (something like todays date - 90 days)

Hi @BTanaji

Try this linq expression:

filteredData = YourDataTableVariable.AsEnumerable().Where(Function(row) DateTime.ParseExact(row("Last Logon").ToString(), "M/d/yyyy", System.Gobalization.CultureInfo.InvariantCulture) >= DateTime.Today.AddDays(-90)).CopyToDataTable()

filteredData is of DataType System.Data.DataTable

Hope it helps!!

we keep in mind:

Assign Activity:
dtFiltered =

(From d in YourDataTableVar.asEnumerable
Let dp = DateTime.ParseExact(row("Last Logon").ToString(), "M/d/yyyy", System.Gobalization.CultureInfo.InvariantCulture)
Where dp.Date < DateTime.Now.AddDays(-90).Date
Select r =d).CopyToDataTable

As mentioned above within the FirstAid we check the DataTable and align the DateTime parsing accordingly

Handling empty results:

Feel free to adapt the LINQ e.g. by handling empty row values / non parseable values etc