hi, I have an excel data table column “DATE_TIME” contains date time in string “yyyyMMddHHmm”, I wanted to filter my datatable, keep all the data from (Day-3, 13:00 PM) to (Today, 08:00).
Currently I am using this,
DT.AsEnumerable().Where(Function(Row) DateTime.ParseExact(Row(“DATE_TIME”).ToString(), “yyMMddHHmm”, CultureInfo.InvariantCulture).Date >= New DateTime(Now.AddDays(-3).Year, Now. AddDays(-3).Month, Now.AddDays(-3).Day,13,0,0) AND DateTime.ParseExact(Row(“DATE_TIME”).ToString(), “yyMMddHHmm”, CultureInfo.InvariantCulture).Date < New DateTime(Now.Year, Now.Month, Now.Day,13,0,0)).CopyToDataTable()
but it give me error “Assign: the source contains no DataRows”
please help me out
@Kevin_Maurice , The error due to there is no data after filtering the date. You are trying to filter the past 3 days’ record with today’s date. But Excel has a record of June month. So the data will empty.
So use the If condition with Count. and the count is greater than zero, they copy the data into a data table and process it.