Order by on String's substring in Linq

I have a date field for which I convert the value of the database from datetime to string format("dd-MMM-yyyy"), I need to perform sorting this string date field, but seems like when I have been doing the sorting, it is working and checking only the date, not the month as well as not the year. So when the data is in date format (database):

2012-01-29
2011-01-01
2013-03-28

So it is sorted like

2013-03-28
2012-01-29
2011-01-01

But it is sorted: 29-Jan-2012 28-Mar-2013 01-Jan-2011

So I want to apply orderbydescending-> then by-> so on, I need to split the string from end, is there a way around? I am doing:

List<c> lst=lst.OrderByDescending(d=>d.TDate.Substring(d.TDate.LastIndexOf('-').toList();

Answers


How about this,

List<string> lst= new List<string>{"29-Jan-2012", "28-Mar-2013", "01-Jan-2011","2011-01-01","2013-03-28"};
lst.OrderByDescending(x=>DateTime.Parse(x));

in your sample it should be,

lst.OrderByDescending(x=>DateTime.Parse(x.TDate))

Need Your Help

CMake unresolved externals

c++ visual-studio-2013 cmake linker-error

I am trying to compile a very simple CMake project using Visual Studio 2013, however I am getting the following error upon trying to compile it:

Can't paint on JPanel after clearRect() and repaint()

java swing jframe jpanel paint

I have a program which lets the user paint. But when the user clicks the clear button which calls clearRect() and repaint() the user can no longer keep painting on the same panel. Another issue I am