Remove rows from DT which have date later than a provide date

How do i remove rows from a DT where the date string yyyyMMdd from a column is later than the provided date variable, without using for each loop if possible?

date variable = 03052023

date var is in ddMMyyyy

Hi @TyraS

Please try the following query in an Assign activity:

filteredRows = yourDt.Select("DateTime.ParseExact(dateColumn, 'ddMMyyyy', System.Globalization.CultureInfo.InvariantCulture) <= DateTime.ParseExact('" + providedDate + "', 'ddMMyyyy', System.Globalization.CultureInfo.InvariantCulture)").CopyToDataTable()

Hope this helps,
Best Regards.

Hello @TyraS ,

Try below logic. Hope it helps

(From p In dt.Select() Where (From q In dt.Select() Where DateTime.ParseExact(q("Column1").tostring,"ddMMyyyy",System.Globalization.CultureInfo.InvariantCulture)<(DateTime.ParseExact(p("Column1").tostring,"ddMMyyyy",System.Globalization.CultureInfo.InvariantCulture)) Select q).toArray.count>1 Select p).ToArray.copyTodatatable()

**NOTE : **
dt : is variable of type datatable
“Column1” : is your date column

2 Likes

got this error : The expression contains undefined function call DateTime.ParseExact().

hi @pavithra_pavi , i tried to modified the code, but it seems to not filter.

(From p In dt.Select() Where (From q In dt.Select() Where DateTime.ParseExact(q(“Column1”).tostring,“yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulture)<(DateTime.ParseExact((DateTime.ParseExact(“01092022”, “ddMMyyyy”, System.Globalization.CultureInfo.InvariantCulture).toString(“yyyyMMdd”)),“yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulture)) Select q).toArray.count>1 Select p).ToArray.copyTodatatable()

can you share your code? to understand better.

In my LINQ query, i used “Column1” Does your code has same name for column? If Not, please change it

i.e.,

(From p In dt.Select() Where (From q In dt.Select() Where DateTime.ParseExact(q(“Column1”).tostring,“ddMMyyyy”,System.Globalization.CultureInfo.InvariantCulture)<(DateTime.ParseExact(p(“Column1”).tostring,“ddMMyyyy”,System.Globalization.CultureInfo.InvariantCulture)) Select q).toArray.count>1 Select p).ToArray.copyTodatatable()

dt.AsEnumerable().where(Function (row) DateTime.ParseExact(row("Column1").tostring,"yyyyMMdd",System.Globalization.CultureInfo.InvariantCulture)<=(DateTime.ParseExact(dateVar,"yyyyMMdd",System.Globalization.CultureInfo.InvariantCulture))).CopyToDataTable

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