I am doing a POC to scrap Ratings and Reviews from Amazon.com. Reading the data in the data table is working fine. However I am using Filter wizard to remove any reviews older than current day minus 2 days using ‘Datetime.Now.AddDays(-2).ToString(“MM/dd/yyyy”)’. This part is not working.
The date on the website is in May 18, 2018 format. I am using filter wizard soon after reading the data from the website using ‘Data Scraping’ and before writing it to the excel.
Once you scrap the data, it will be stored in datatable. So you need to convert string values in datatable to date type while applying the filter and write filtered datatable to an excellent file.
@agoyal1980
Give a try on doing IT with a linq Statement
Use an assign Activity
In right Side:
YourDataTableVar.dtDemo.AsEnumerable.Where(Function (row) Convert.ToDateTime(row(0).tostring)>= Datetime.Now.AddDays(-2)).CopyToDataTable
Left Side assign e.g dtFiltered - Datatype is datatable
@agoyal1980
In a next round once you got this working then I would suggest to change
Convert.ToDateTime to a stronger Conversion method that let you aloow to get control with a format string
DateTime.ParseExact() Method would be a recommendable option
Example: Datetime.ParseExact(YourDateTimeString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
System.Globalization.CultureInfo.InvariantCulture or your specific CultureInfo
the result is filtering and keeps only the matching rows. If you assign to your origin datatable then its like removing the not matching rows. If you assign to another Datatable (I would suggest) then result is same (only the matching rows) but you have not lost the other rows. Does it answer your question?
I used your ExtractDataTable.AsEnumerable.Where(Function (row) Convert.ToDateTime(row(“ReviewDate”).tostring)<= Datetime.Now.AddDays(-2)).CopyToDataTable in assign and then wrote to excel. however the old records are still showing up.