Sort array of Date Time in descending order

Hi @Sairam_RPA ,

I am assuming that the format is day-month-year-time, and that there are only two different types of format and if that is the case, then here is an alternative solution →


First, we will declare an Array of Formats →

arr_strFormats = {"d/M/yyyy h:mm tt","dd.MM.yyyy h:mm tt"}

Next, we will use an overload from the DateTime.ParseExact method that takes an array of formats as argument.

To order the date in Ascending order, we simply have to order it, since the items are ordered in Ascending order by default →

arr_strDates.OrderBy(Function(o) DateTime.ParseExact(o.ToString,arr_strFormat,Nothing,Nothing)).ToArray()

And to order it from latest to old, we have to Order By Descending →

arr_strDates.OrderByDescending(Function(o) DateTime.ParseExact(o.ToString,arr_strFormat,Nothing,Nothing)).ToArray()

Here is a workflow for your reference.
ArrangeDates.xaml (6.7 KB)

Kind Regards,
Ashwin A.K

1 Like