My input data issue for automation

in this excel i have to delete last 10 days data based on checking M column InvDT
we have to delete the last 10 days rows of data

in my excel M column i have thi data

InvDT
04/30/2024
04/30/2024
04/29/2024
04/29/2024
04/28/2024
04/28/2024
03/13/2024
04/09/2024
04/11/2024

here my excel problem is this dates are coming in string format which conatins spaces in front and back of dates its taking like string i have tried filter data table but idid not work
check my execel attachment
can you try by linq and share me soultion in detail

Thanks in Advance
Fabbucket
SQL.xls (1.2 KB)
@ppr

Hi @Fab_Bucket

can you please try with below linq query.

filteredData = dt.AsEnumerable()
.Where(row => row.Field(dateColumnName) >= currentDate.AddDays(-10) && row.Field(dateColumnName) <= currentDate)
.CopyToDataTable();

Hope it helps!!!

yourRowVar(“InvDT”).toString.Trim should cleanse the value

e.g.

(From d in dtData.AsEnumerable
Let ds = d("InvDT").toString.Trim
Let dp = YourDateTimeParseStrategy(ds........).Date
Where dp #your-last-10-Days-Check#
Select r =d).CopyToDataTable

You can prototype within the immediate panel
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

And analyze as described here:
:ambulance: :sos: [FirstAid] Datatable: Debug & Analysis invalid DateTime Strings / String to DateTime Parsing Issues - News / Tutorials - UiPath Community Forum

@Baskar_Gurumoorthy

please share with us the passed compiler screenshot. Thanks

@Fab_Bucket

what was done so far at your end?

I am getting complier errors can you execute and share me solution

I am getting complier errors can you execute and share me

Hey, we did support with starter help, and requested your part results

Assign Activity
dtFiltered =

(From d In dtData.AsEnumerable
Let ds = d("InvDT").toString.Trim
Let dp = CDate(ds).Date
Where Not ( dp >= Now.AddDays(-10).Date And dp <= Now.Date )
Select r =d).CopyToDataTable

sorry that is c# code better can you try this .

Dim filteredData = dt.AsEnumerable().Where(Function(row) row.Field(Of DateTime)(“YourDateColumnName”) >= DateTime.Now.AddDays(-10) AndAlso row.Field(Of DateTime)(“YourDateColumnName”) <= DateTime.Now).CopyToDataTable()

i don’t have system with me at the moment thats why i am providing only query .

Assign: Conversion from string “” to type ‘Date’ is not valid. i am getting this error

i am getting this error Assign: Specified cast is not valid.

kindly assign only filtered_Data as data table variable don’t use dim.

also you can replace yourdatacolumn to your column name.

yes i am not using dim and replaced my my column but i am getting error

can you try the below one.

filteredData = dt.AsEnumerable().Where(Function(row)
Dim dateValue As DateTime
Return DateTime.TryParse(row.Field(Of String)(“YourDateColumnName”), dateValue) AndAlso
dateValue >= DateTime.Now.AddDays(-10) AndAlso
dateValue <= DateTime.Now
End Function).CopyToDataTable()

no same i am getting compiler errors can you try once you reach home.

okay please share your workflow.

due to vpns iam unable to share sorry i have given info in my question

is about a value which is an empty string and not in relation with the LINQ

we can filter out e.g. by

(From d In dtData.AsEnumerable
Let ds = d("InvDT").toString.Trim
Where not String.IsNullOrEmpty(ds)
Let dp = CDate(ds).Date
Where Not (dp >= Now.AddDays(-10).Date And dp <= Now.Date )
Select r =d).CopyToDataTable

But as mentioned and shared

do the adhoc analysis and check for the details

the filter of data is not working correctly we have to delete last 10 days data rows in excel based on InvDT column
Thanks in advance

@Fab_Bucket
please tell details as we cannot derive:

  • wrong filter result
  • any other issues

As our starter helps can be adapted by your self as well, maybe you can finalize by your own also

LINQ Learning:
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum