I need to filter a datatable dt, which is having 50 plus columns and there is one column which is document date. I have two variable in which I have “From Date” and “To date”, means I have to get only data from datatable, which fall under the range of from date and to date variable. I am trying through filter data table, but it is not correctly working. Please help me. If I have from date 01-03-2023 and to date is 05-03-2023 then all rows should be returned which is having 01,02,03,04,and 05 date
you can try this once it will helps you
dt.AsEnumerable.where(function(a) CDate(a(“ColumnName”).ToString)>=CDate(“01-03-2023”) andalso CDate(a(“ColumnName”).tostring)<=CDate(“05-03-2023”)).CopyToDataTable
That’s the problem. The columns in the datatable need to be datetime.
Use Add Data Column to add two datetime columns. For Each Row in Datatable with Assigns to convert the string dates into actual datetime values (DateTime.Parse or DateTime.ParseExact) into the datetime columns.