How to retrieve previous 7 days data from today

I have data like this in excel


I need to retrieve records based on the MailSentDateTime Column Where Only 7 day previous records should get picked.

Resulting Excel should be :


Excel File -
Book1.xlsx (11.9 KB)

Hi @Ishan_Shelke ,

Could you maybe check on the below Expression :

DT.AsEnumerable.Where(Function(x)CDate(x("MailSentDateTime").ToString).Date<Now.Date andAlso DateDiff(DateInterval.Day,CDate(x("MailSentDateTime").ToString).Date,Now.Date)<=7).CopyToDatatable

Let us know if this doesn’t work.



Multiple ways

  1. Use filter activity in excel to filter the rows based on the days conditions…youc an select the number of days you want to filter
  2. Read the dat into datatable and use Filter datatable as "MailSendDateTime" > Now.Adddays(-7)
  3. Using linq dt.AsEnumerable.Where(function(x) Cdate(x("MailSentDateTime").ToString) > Now.Adddays(-7)).CopyToDatatable

Hope this helps


This is only fetching the 7th day data i.e 16th March, I need all the data from the last 7 days

Hi @Ishan_Shelke

  1. You can try with this LINQ expression
(From row In dtData.AsEnumerable()
Where row.Field(Of DateTime)("MailSentDateTime") = DateTime.Now.AddDays(-7)
Select row).CopyToDataTable()

This will retrieve the data from the dtData datatable where the Date column is greater than or equal to 7 days ago from today’s date. You can then use the CopyToDataTable() method to copy the filtered data to a new datatable


Hey @Ishan_Shelke
Try this
Excel Tsk (77.7 KB)


Hope it helps

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.