From current date datas to oldest one

Hi guys,

I’m reading excel and keeping all datas to dt_Datas variable. I need to filtered on this dt table.
I need to getting datas from current day to oldest.
I used filter data table but didn’t work.
ColumnName : RegDate => Type of Date in excel.

I need some help.

Thank you.

Hi,

Try this Linq query and see if it is what you need.

dt_Datas = dt_Datas.AsEnumerable().Where(Function(row) DateTime.Parse(row("RegDate").ToString()) <= DateTime.Now).CopyToDataTable()

1 Like

It worked. Thanks.

But if there is no match data it gives the error like “The source contains no DataRows”
When i check the main DT there are 3 datas and these datas are not old.
These error occured on assign activity.

How can i control this?
ex : if DT includes old date then run

dt_Datas = dt_Datas.AsEnumerable().Where(Function(row) DateTime.Parse(row(“RegDate”).ToString()) <= DateTime.Now).CopyToDataTable()

otwerwise continue.

You can put the following query in an IF activity:

dt_Datas.AsEnumerable().Any(Function(row) DateTime.Parse(row(“RegDate”).ToString()) <= DateTime.Now)

If the above is true then it will go to the “Then” part and you can do the previous step.

Keep in mind that the below cant handle empty strings/values or strings/values that are not in the correct format, if you expect no data or incorrect format that the Linq query below needs to be modified or similar.

dt_Datas = dt_Datas.AsEnumerable().Where(Function(row) DateTime.Parse(row("RegDate").ToString()) <= DateTime.Now).CopyToDataTable()

1 Like

Thanks alot. :slightly_smiling_face:

Best wishes. :innocent:

No problem.

Just try out some different scenarios with the data/cell values and dates to verify that it works as you need it to.

Good luck.

1 Like

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