I need to create a new data table with dates greater than the date two days before today’s date. (Today’s date is 21.10.2024, so the desired date is > 19.10.2024)
Date_y
25.10.2024
30.10.2024
28.10.2024
I would be happy if you could help me with this, thank you,
Also it would be better to use if codnition first to check if alteast one row satisfies this condition …use dt.AsEnumerable.Where(function(x) Cdate(x("Date_x").ToString) > Now.AddDays(-1)).Count>0
on then side use assign with above…on else side no rows are present so can emtpy the datatable or reinitialize dt = New Datatable()
Hi @alper_ozyurt
try with this
dt.AsEnumerable().Where(Function(row) DateTime.ParseExact(row(“Date_x”).ToString(), “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture) > Now.AddDays(-2)).CopyToDataTable()
Can you try
dt.AsEnumerable().Where(Function(row) DateTime.ParseExact(row(“Date_x”).ToString(), “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture) > Now.AddDays(-2)).CopyToDataTable()
can try this one
dt_filtered = dt_data.AsEnumerable().Where(Function(row) DateTime.ParseExact(row(“Date_x”).ToString(), “MM/dd/yyyy HH:mm:ss”, System.Globalization.CultureInfo.InvariantCulture) > Now.AddDays(-2)).CopyToDataTable()
Step 5
Add Data Row: Add the row to the dt_filtered table.
In the end, you will have the dt_filtered table with the dates that are greater than two days before the current date. In your example, the dates greater than 10/19/2024 are: