Filter only for dates that are 45 days later than today

Hi, I have Excel with the date in the format: yyyy-mm-dd. I would like the robot to filter out all rows that have a date + 45 days from today’s date.

Hi @sullivanne

Try this LINQ expression:

filteredDataTable = inputDataTable.AsEnumerable().Where(Function(row) DateTime.ParseExact(row("DateColumn").ToString(), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) <= DateTime.Today.Adddays(45) andalso DateTime.ParseExact(row("DateColumn").ToString(), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) >= DateTime.Today).CopyToDataTable()

Regards

@sullivanne

targetDate=DateTime.Now.AddDays(45)
filteredRows=dt.AsEnumerable().Where(Function(row) DateTime.ParseExact(row("DateColumn").ToString(), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) <= targetDate).CopyToDataTable()

Note that as written this will also take into account the time. If you only want the date itself considered, then change…

targetDate=DateTime.Now.AddDays(45)

…to…

targetDate=New DateTime(Now.Year,Now.Month,Now.Day,23,59,59)