Skip to content

Sort Array by Date

yurikoex

Asked Nov 1, 2005, 5:55 AM EST1 answer
Share
LinkedInX

I'm trying to find the straight forward way to sort a single array of dates.

here is a sample...
i want this:
12/27/2005
12/28/2005
01/01/2006
01/02/2006
01/04/2006
01/05/2006
12/29/2005
12/30/2005
12/31/2005
01/03/2006


to look at this:
12/27/2005
12/28/2005
12/29/2005
12/30/2005
12/31/2005
01/01/2006
01/02/2006
01/03/2006
01/04/2006
01/05/2006

any clues?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You can create a DateTime array and use the Array.Sort method:

    First initialize 3 DT variables:
    Java
    DateTime d1= new DateTime(2005,10,20);
    DateTime d2= new DateTime(2005,7,22);
    DateTime d3= new DateTime(2005,12,25);
    Put them in the array:

    DateTime [] dates = {d1,d2,d3};

    Call the Array.Sort static method:

    Array.Sort(dates)

    0