Filter excel datatable by Date Time (yyyyMMddHHmm)


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


The errors says that with this filter there are zero rows that are identified…

As a proactive measure instead of .copytodatatable use .count and check the count first and if it is greater than zero then use .CopyToDaTatable

Hope this helps


@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.

:ambulance: :sos: [FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum

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