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
You only need 1 filter activity. Click on the [ + ] icon to right to add another filter value.
However this filter will only work if the target column has a DateTime format. So if it doesn’t work, check the input (or use the dt.select option to convert while filtering)
You said it’s a datatable. What’s the datatype of the column in the datatable? If you’re using Read Range or one of the Excel activities to read into the datatable then it’s probably a string column.
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.
The column need not be readily available in DateTime data type to proceed with the execution. You can basically take the instance of the data & parse it during the runtime & get the required output.