CSV Date Filter Issue

excel
studio

#1

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


#2

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


#3

Hi @Susana

Thanks for the solution. It worked perfectly.

:slight_smile:


#4

hi,

Please check the tutorial,

Thanks,
Karthik