Hi Guys I have an array of date time values like below:
{“4/5/2022 1:02 PM”, “4/5/2022 3:39 PM” “4/5/2022 3:28 PM” “4/5/2022 1:15 PM” “01.08.2019 2:20 AM”}
Could someone help me with sorting them based on the date time in descending order.
Hi Guys I have an array of date time values like below:
{“4/5/2022 1:02 PM”, “4/5/2022 3:39 PM” “4/5/2022 3:28 PM” “4/5/2022 1:15 PM” “01.08.2019 2:20 AM”}
Could someone help me with sorting them based on the date time in descending order.
hey
first of all you need to standarize your dates to the same format, you can loop through you loop and format all.
for this example: i used formart MM/dd/yyyy hh:mm tt
arrayDate = {"04/05/2022 01:02 PM", "04/05/2022 03:39 PM","04/05/2022 03:28 PM","04/05/2022 01:15 PM","01/08/2019 02:20 AM"}
order
arrayDate = arrayDate.OrderBy(Function(d) DateTime.ParseExact(d, "MM/dd/yyyy hh:mm tt", System.Globalization.CultureInfo.InvariantCulture)).ToArray()
ouput:
hope it helps
regards!
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
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.