CSV Date Filter Issue

Hi,

I’m trying to filter the CSV data after a particular date. But filter is returning wrong number of records.
CSV file is received through an e-mail. PFA code file.

Steps I’m following are

  1. Read CSV into data table

  2. Apply filter on data table. (Date >= 2nd Nov 2017)
    dt.Select(“Date>='”+Convert.ToDateTime(“02/11/2017”).ToShortDateString()+" “+Convert.ToDateTime(“02/11/2017”).ToShortTimeString+”'")

  3. Store the filtered data in another excel.

Date format is dd/MM/yyyy

CSV Filter.zip (3.4 KB)

Can anyone help?
Thanks

Hello @ShubhankarJogalekar,

Try to define your CurrentCulture and then use dtInputData.AsEnumerable().Where(Function(row) Convert.ToDateTime(row(“Joining_Date”).ToString) >= Convert.ToDateTime(“02/11/2017 00:00”)).ToArray()

Main_option1.xaml (17.9 KB)

Or you can try directly

dtInputData.AsEnumerable().Where(Function(row) Date.ParseExact(row(“Joining_Date”).ToString,“dd/MM/yyyy HH:mm”,System.Globalization.CultureInfo.InvariantCulture) >= Date.ParseExact(“02/11/2017 00:00”,“dd/MM/yyyy HH:mm”,System.Globalization.CultureInfo.InvariantCulture)).ToArray()

Main_option2.xaml (16.4 KB)

Regards,
Susana

4 Likes

Hi @Susana

Thanks for the solution. It worked perfectly.

:slight_smile:

hi,

Please check the tutorial,

Thanks,
Karthik