Reputation: 33
I have an array of dates from this form:
string[] arr=["08.02.2017","09.02.2017","30.01.2017","31.01.2017"]
what is the best way to sort this kind of array in c#? I want that the order will of the array will be in descending order. I need to show this data inside an select element, maybe i can order this somehow with angularJS?
Upvotes: 0
Views: 80
Reputation: 460158
You can do it in C#:
arr = arr.OrderByDescending(s => DateTime.Parse(s, new CultureInfo("de-DE"))).ToArray();
Another way with ParseExact
:
arr = arr.OrderByDescending(s => DateTime.ParseExact(s, "dd.MM.yyyy", null)).ToArray();
Upvotes: 1