Problems extracting the minimum date from a datatable

I am trying to extract the minimum date in the column of a datatable (RegistDT) where the format of the dates is as follows (3/18/2021), the instructions I have tried to use are:

Convert.ToDateTime(RegisDT.Compute("MIN(Date)",null))
and
Convert.ToDateTime(RegisDT.AsEnumerable().Min(Function(row) row(“Date”)))

None has worked for me, in the first instruction Uipath told me that I was misusing the MIN (), and in the second it told me that the object should be of type string, I tried to make corrections and it has not worked for me. I think it is because of the format of the date values ​​but I am not sure how to solve it, any suggestions?

Please try this…

  Convert.ToDateTime(RegisDT.AsEnumerable().Min(Function(row) row(“Date”).tostring)

I had already tried that correction, the error that UiPath gives me in that case is:

“String was not recognized as a valid DateTime”

@JavXult - I tesed the below code and it worked for me…

  cdate(RegisDT.AsEnumerable().Min(Function(row) cdate(row("Date")).tostring)).tostring
1 Like

@JavXult

RegisDT.AsEnumerable().OrderBy(Function (x) Convert.ToDateTime(x(“Date”).toString.Trim)).First()
Or
RegisDT.AsEnumerable.Min(Function (x) CDate(x(“Date”).toString.Trim))

grafik

If it is failing, then in often cases the format is not valid / different

  • set breakpoint
  • debug and get paused
  • open immediate panel
  • run analyzer statement:
    dtData.AsEnumerable.Where(Function (x) Not DateTime.TryParse(x(“Date”).toString.Trim,nothing)).ToList
2 Likes

It worked! @prasath17 Thank you very much !!, My problem was that the excel workbook I was using had an extra row for the totals of some values, therefore it had empty cells.

Both cases worked once my problem with the extra row was corrected, Thank you very much @prasath17 as always and also for the both options for different scenarios! you are a big one.

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