Trying_To_Know
Trying_To_Know

Reputation: 33

Sort an array of strings that contain a dates in C# or order by in angularJS?

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

Answers (1)

Tim Schmelter
Tim Schmelter

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

Related Questions