How to extract oldest date and latest date in datatable

Hi there,

I have a datatable extracted from a csv file.
The datatable has multiple columns and one of them is a date column which is a string type.
I could read range from csv file, but cannot extract oldest (min) and latest (max).

I tried this below image referencing from this post: Select(find) max date from datatable .

Dt.AsEnumerable().Max(Function (drRows) DateTime.Parse(drRows.Item(8).ToString)).ToString

However i got an error:

How do I get this correctly??

Exception occurs if the date string is within a form that is not parseable by the DateTime.Parse method.

I that case a quick analysis on data from the datatable will help

  • set a break point on relevant location
  • debug the bot and get pause
  • open immediate panel
  • use following statement: dt.Rows(0)(8).toString

please share the output with us, so we can further help. Also check the CSV file that all dates are consistent in the format and not empty

Thank you for your reply.

I have never used immediate panel and am not sure if i did it right. but here’s the output.

I checked the csv file and the dates are consistent since it was downloaded file.

Perfect you have done correctly

175 is not a date string. Kindly note column index is 0 based. Maybe the date is within another column. Can you check this please? Thanks

You are right.
I put a wrong column index. :woman_facepalming:

I spent a lot time to solve this, and didnt even notice that.

Thank you so much for your time.

Perfect. Issue is identified. This can happen to all of us.
Just do your final testing. Let us know your further open questions. Once it is working please mark the solving post as solution. So others can benefit from it.


1 Like

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