DataTable.Select() date range

Hello UiForum,

I’m having some issues when trying to filter using dt.Select() method.

My sequence is like the following:

read csv activity create dt # retrieve data
dateend = new datetime(now.year, now.month, # create end range date
dateinit = datend.AddDays(-2) # create start range date
dt = dt.Select( "[date] >= #"+ dateinit.ToString +"# AND [date] <= #" + dateend.ToString +"#").CopyToDataTable # filtering dt

When I run this script a runtime execution error occur that says “The Source contains no DataRows”
But my dt does contains the dates I’m filtering.

These datetimes are formatted mm/dd/yyyy hh:mm:ss in the original source.

If I change to a larger dateinit it does work.

I dont understand why it works in certain condition but not in others, can you guys help me out to spot the problem?

1 Like

Hello Welcome, I had this issues. but its okay now, first you have to use that entire data table select function in a try catch
Hold on let me send you a sample sequence.
When ever you get the error , that the source contains no data rows it simply means the date items are not there . so you need to catch it as an exception and keep going

Sample.xaml (11.9 KB)

Hello, Please find attached .

read your data table into dtInputData and your output comes out in dtoutput.

there is a string vraible “errormessage” which catches any error should in case one occurs. example of an error is when you are filtering for a date that is not present on the data table.
so if the string variable is not null or empty it then it means the data you are looking for was not present and it continues without stopping your process.

Also make sure that if you are filtering for rows that falls between dates ensure to include the time.

i.e filtering data btwn "13/03/19 " and “15/03/19” my actual strings would be like this
Start = “13/03/19 00:00:00”
End = “15/03/19 23:59:59”
That is what i did in the series of assign activities before the invoke code


Thanks David.

I’ll Catch the process but I know the dates exists in the dt, that’s why I’m confusing that my method it is not working, I’m testing your solution and letting you know if suits for me,

I have a question, what would be the changes if I use MM/dd/yyyy Date Format?

image in this assign activity change each of the values to Datetime.parseexact(yourdate,“MM/dd/yyyy”,system.globalization.cultureinfo.invariantculture)

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