Hi Everyone,
I am stuck with a problem , I need to filter previous months data from a datatable (Dynamically).
excel should have all data that is prior to the same month.
eg: if you run on 1st March 2022 – all data till 28 Feb 2022 would be there.
eg: if you run on 28th Feb 2022 – all data till 31st Jan 2022 would be there.
since current month is Feb. => I required prior month data (i.e. , Jan as highlighted in above screenshot).
I’ve tried different ways ; If anyone can share any insights , ideas or LINQ queries it would be helpful.
Below Linq Query can be used to filter for previous month dates:
in assign activity :
dt1=
dt1.AsEnumerable.Where(function(row) Cdate(row(“Date”).ToString) >=date1 and C
date(row(“Date”).ToString) <= date2).CopyToDataTable
where dt1 → input datatable
date1 → New DateTime(Now.Year,Now.Month,1).AddMonths(-1) → previous month first day date
date2 → New datetime(now.Date.Year, now.Date.Month,1).AddDays(-1) → previous month last day date.
In this way, previous month date values can be filtered.
Hope this helps.
(From r in dt_test.Select()
Where Datetime.ParseExact(r("Date").toString,“dd-MM-yyyy”,System.Globalization.CultureInfo.InvariantCulture).Month = DateCheck.AddMonths(-1).Month
Select r).CopyToDatatable
@rameespk23 you could use filter data table (or linq) to filter the data column >= 01.01.actual year and < first day of the actual month. Only the data for the previous months would remain.
(From r in dt_test.Select()
Where Datetime.ParseExact(r("Date").toString,“dd-MM-yyyy”,System.Globalization.CultureInfo.InvariantCulture).Month < Datetime.Now.Month
Select r).CopyToDatatable