I would like to filter a data table.
If the Due Date column is > DateTime.Today.AddMonths(3).AddMonths(1).AddDays(-DateTime.Today.Day, I want to keep the rows.
I have the following table:
Due Date Days Overdue
16.10.2021 646
08.02.2024 531
03.05.2022 447
My Invoke Code:
Dim ThreeMonths As DateTime = DateTime.Today.AddMonths(3).AddMonths(1).AddDays(-DateTime.Today.Day)
Try
Dim filteredRows = dtDateSort.AsEnumerable().Where(Function(row) DateTime.ParseExact(row(“Due Date”).ToString(), “dd.MM.yyyy”, Nothing) < ThreeMonths).CopyToDataTable()
Catch ex As Exception
Throw ex
End Try
Arguments: dtDateSort in/Out Datatable dtDateSort
The code seems to be theoretically correct, but it does not work.
Dim ThreeMonths As DateTime = DateTime.Today.AddMonths(3).AddMonths(1).AddDays(-DateTime.Today.Day)
Try
Dim filteredRows = dtDateSort.AsEnumerable().Where(Function(row) DateTime.ParseExact(row("Due Date").ToString(), "dd.MM.yyyy", Nothing) > ThreeMonths).CopyToDataTable()
dtDateSort = filteredRows ' Assign the filtered DataTable back to the original DataTable
Catch ex As Exception
Throw ex
End Try
Dim ThreeMonths As DateTime = DateTime.Today.AddMonths(3).AddMonths(1).AddDays(-DateTime.Today.Day)
Try
Dim filteredRows = dtDateSort.AsEnumerable().Where(Function(row) DateTime.ParseExact(row("Due Date").ToString(), "dd.MM.yyyy", Nothing) > ThreeMonths).CopyToDataTable()
' Use the filteredRows DataTable as needed
Catch ex As Exception
Throw ex
End Try
Try
Dim filteredRows = dtDateSort.AsEnumerable().Where(Function(row) DateTime.TryParseExact(row(“Due Date”).ToString(), “dd.MM.yyyy”, CultureInfo.InvariantCulture, DateTimeStyles.None, Nothing) < ThreeMonths).CopyToDataTable()
’ Do something with the filteredRows datatable here…
Catch ex As Exception
Throw ex
End Try
Ideally you dont need an invoke code you can do in assign directly…anyways…its not working because you are not passing the modified datatable filteredrows out