2

If I have dates such as 23/05/2011, 17/03/2012, 01/07/2010 etc. in a string array is it possible to sort the years first then months then days instead of it sorting the days first?

2
  • 4
    if they are in a string array they are strings (not Dates) because string arrays hold...well, you know Commented Mar 30, 2015 at 19:49
  • 3
    Yes, but first you should ask yourself if the string array should be a string array instead of a DateTime array. Commented Mar 30, 2015 at 19:50

1 Answer 1

6

You could parse them to DateTime first:

var orderedByDateTime = strings
    .Select(s => new { s, dt = DateTime.ParseExact(s, "dd'/'MM'/'yyyy", null) })
    .OrderBy(x => x.dt)
    .Select(x => x.s);
Sign up to request clarification or add additional context in comments.

Comments

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.