To find column has date or not

I have query to find the max date.
Before that I need to check that particular row of column value is in the date format or not
If it is in date format only I will check max date

Query is below,
dt.AsEnumerable.ToList.ForEach(Sub(r) r(18) = If(Not String.IsNullOrEmpty(r(9).ToString) AndAlso CDate(r(5).ToString)>CDate(r(9).ToString),“Quality is best”,If(Not String.IsNullOrEmpty(r(9).ToString) AndAlso CDate(r(5).ToString)>CDate(r(11).ToString),“Quality is best”,If(Not String.IsNullOrEmpty(r(9).ToString) AndAlso CDate(r(5).ToString)>CDate(r(13).ToString),“Quality is best”,If(Not String.IsNullOrEmpty(r(9).ToString) AndAlso CDate(r(5).ToString)>CDate(r(15).ToString),“Quality is best”,If(Not String.IsNullOrEmpty(r(9).ToString) AndAlso CDate(r(5).ToString)>CDate(r(17).ToString),“Quality is best”,“Quality is Worst”))))))

we would recommend to rework on the approach, as the forced usage of LINQ is over-LINQing it.

  • too much redundancies on doing the same (e.g. repeated CDate(r(5)
  • too nested if checks
  • the optimistic approach that every non empty string is a parseable date vs. DateTime.TryParseExact