0

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?

2
  • In c# or angularjs ? Commented Feb 9, 2017 at 13:09
  • Don`t mind, both will be a good solution for me Commented Feb 9, 2017 at 13:10

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

1 Comment

@Trying_To_Know: i have used de-DE because we use . as date-separator. You might also use your own.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.