Sort by the last 4 digits, latest date

Hello,
Im new in UiPath automation, so i need that from excel column would take the line with the latest date.The date is at the lines end 4 digits. Like in the column is EN 13480-3:2017,
EN 13480-3:2017/A3:2019,
EN 13480-3:2017/A2:2020, , and i need that it would take the line with the latest date EN 13480-3:2017/A2:2020.So what do i need to value to save it?

Hi,

How about the following expression?

targetDataRow = dt.AsEnumerable().OrderBy(Function(r) CDbl(System.Text.RegularExpressions.Regex.Match(r("Column1").ToString,"....$").Value)).Last()

OR

strVar = dt.AsEnumerable().OrderBy(Function(r) CDbl(System.Text.RegularExpressions.Regex.Match(r("Column1").ToString,"....$").Value)).Last.Item("Column1").ToString

Regards,

Hello,

Please check the below options (vb codes), it should work

LINQ

LatestRow = dtData.AsEnumerable().
    OrderByDescending(Function(row) Convert.ToInt32(row("ColumnName").ToString().Substring(row("ColumnName").ToString().Length - 4))).First()

SELECT Query

Dim latestRow As DataRow = dtData.Select().
    OrderByDescending(Function(row) CInt(Regex.Match(row("ColumnName").ToString(), "\d{4}$").Value)).
    FirstOrDefault()

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