Archive

Posts Tagged ‘date sorting’

Order by Date Descending issue (Linq)

February 12, 2016 Leave a comment

Issue :

 Dim list As List(Of Eventlist) = (From d In EventList
 Order By d.Status Descending, d.StartDate Descending, 
 Select d).ToList()

It gives me the date ordered by month and day, but doesn’t take year into consideration. for example:

12/31/2009 
12/31/2008
12/30/2009
12/29/2009

Needs to be more like:

12/31/2009
12/30/2009
12/29/2009
12/28/2009

Solution :

 Dim list As List(Of Eventlist) = (From d In EventList
 Order By d.Status Descending, Year(d.StartDate) Descending, Month(d.StartDate) Descending, Day(d.StartDate) Descending
 Select d).ToList()


Hope it helps !