Date condition

I am using CSV file as input and writing to Excel file.
how to filter the records from the datable based on the date condition.My format of date in my file is MM/DD/YYYY
I am using the condition as follows: bookdata.Select(“Published_Date >= #11/30/2017#” ).
But it is picking up all the records.Can anyone help on this?

below is the data from my CSV file.

Author_name Book_name Price Published_Date
Vikas Tamil book 25 10/25/2017
cavendish Maths book 50 11/1/2017
SAP Science book 23 11/12/2017
Pearson Malay book 19 12/5/2017
Marshal History book 30 9/1/2017
Peason Science book 40 9/10/2017

which activity you used to write the data to excel? workbook write range ? or excel application scope?

I am using Excel application scope and inside I use write range activity.The problem is the filter does not work correctly as expected.It picks up all the records from my csv file and write it to excel file.Is my sytax correct in the Select method?

Try this. bookdata.Select(“Published_Date >= '#11/30/2017#' ” )

you can try this

dt.asEnumerable().Where(Function(r) Date.ParseExact(r("Published_Date").tostring,
{"MM/dd/yyyy","M/dd/yyyy","M/dd/yyyy","M/d/yyyy"},Nothing,DateTimeStyles.None) >= `Date.Parse("11/05/2017") ).copytoDataTable 

this doesn’t work.still picks all records.

have you tried this ?

yes.but I get compiler error saying DatasTimeStyles is not may be inaccessible due to its protection level.

go to Imports and import System.Globalization

Actually I am using the select method and assigning it to datavariable of datarow type in Assign activity.
if I use the above code,it gives me the compiler error "Cannot convert to in Assign activity

dt.asEnumerable().Where(Function(r) Date.ParseExact(r("Published_Date").tostring,{"MM/dd/yyyy","M/dd/yyyy","M/dd/yyyy","M/d/yyyy"},Nothing,DateTimeStyles.None) >= Date.Parse("11/05/2017") ).toArray

can I use this in the Assign activity?

yes, assign to array of DataRows it is picking up the filtered records.
How to modify this code to select records between two dates.?

is there any other simple way to get the date based on the date condition?

Select won’t work because in datatable every columns are considered as Object Data Type.
Try this, It May work,

dt.Select(“Convert(Published_Date,System.DateTime) >= '#11/30/2017#' ”) is working fine and I followed the same code to add between twp dates and that also works fine.Thanks for your help and immediate response.

1 Like