Excel filtering1

Hi all,

I am facing with an issue with filter data table.
I have an excel with column name as Expiry Date, in that column I have past date, present date and future dates.
I need to get present and future dates only.
In the filter data table I have given “Expiry Date”>=Today
But this logic is not working.

Please help me.
Thanks in advance

May be the format of the date you are passing might be differnt in the excel and whetever you are passing in the filter condition

Date format is dd-MM-yyyy

Hi @amitha.aenugula

Try this linq query:

filteredDataTable = yourDataTable.AsEnumerable().Where(Function(row) DateTime.ParseExact(row("Expiry Date").ToString(),"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture) >= DateTime.Today).CopyToDataTable()

After enabling Preserve Format, if you get the date format as dd-MM-yyyy the above query will work, or specify the format so that I can help you with updated query.

Hope it helps!!

Hi @amitha.aenugula

Assign activity:
    To: filteredDataTable
    Value: dt.AsEnumerable().Where(Function(row) DateTime.Parse(row("Expiry Date").ToString()) >= DateTime.Today).CopyToDataTable()

@amitha.aenugula

Enable preserve format in Read Range workbook, if you are excel process scope then use property Read Formatting try different options.

Note:Make sure the Formats of Expiry Date and Today have same Formats ,“dd/MM/yyyy” or anything this two variables will contain only one format

@mkankatala Thank you I got it

1 Like

It’s my pleasure @amitha.aenugula

Happy Automation!!

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