Hello, how to filter dates in the datatable +45 days from today’s date?
Thank You! That is, to filter all dates 45 days from today, i.e. August 31, 2024.
Use this LINQ
filteredDT = (From row In dt.AsEnumerable()
Where DateTime.Parse(row("DateColumnName").ToString()).Date = DateTime.Now.AddDays(45).Date
Select row).CopyToDataTable()
Thanks,
Ashok
Hi @sullivanne
You can use the LINQ Expression to filter the data in the datatable which are equals to the +45 days from today date,
→ Use the Read range workbook activity to read the excel and store in a datatable called dt_Input.
→ Then use the assign activity to give the linq expression,
- Assign -> dt_Output = dt_Input.asenumerable.where(Function(X) CDate(X("Column name").toString)= DateTime.Now.Adddays(+45)).Copytodatatable()
→ Then use the write range workbook activity to write the dt_Output to the Excel sheet.
dt_Output is the datatable datatype variable which contains the filtered data.
Hope it helps!!
Hi @sullivanne ,
- Assign:
plaintext
Copy code
todayDate = DateTime.Now.Date
- Assign:
plaintext
Copy code
targetDate = todayDate.AddDays(45)
- Filter Data Table:
- Column:
DateColumn
- Condition:
=
- Value:
targetDate
Regards
Sandy
Read range the excel to a datatable
Take assign activty:
filteredDataTable=inputDataTable.AsEnumerable().
Where(Function(row) DateTime.ParseExact(row("DateColumn").ToString(), "Your Date Format", System.Globalization.CultureInfo.InvariantCulture) > DateTime.Today.AddDays(45)).
CopyToDataTable()
Write Range the datatable