Click here to Skip to main content
15,883,807 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have date listed from a code:

table.Rows.Add(CDate(ud(i)).ToString("MMMM yyyy")

and sorted it using:

C#
Dim view As DataView = table.DefaultView
       view.Sort = "Period Cover ASC"
       Dim sortedDate As DataTable = view.ToTable()




January 2016
December 2015
November 2015
January 2015
February 2015
March 2015
Arpil 2015
May 2015
June 2015
July 2015
Agusut 2015
September 2015
October 2015


but I get:


January 2015
January 2016
February 2015
March 2015
Arpil 2015
May 2015
June 2015
July 2015
Agusut 2015
September 2015
October 2015
November 2015
December 2015

It is still not in order. any help?
Posted

1 solution

if I read this correctly, you're sorting these as strings - I'd be converting them to dates or a custom object with a specific comparer (possible implementing IComparable) to sort them

Maybe there's a way in Linq you can build and compare date Objects on the fly - Im sure there is, I just havnt thought about it too much more
 
Share this answer
 
Comments
NekoNao 3-Feb-16 4:17am    
they are all dates.
Garth J Lancaster 3-Feb-16 6:33am    
as you have shown them, and not showing any other code and/or conversions you have done, they are all string representations of dates - there's a difference

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900