I was wondering if i have 3 random dates.

11/12/2012 9/24/2011 12/29/2008,

I'd like to have

September 9/24/2011

November 11/12/2012

December 12/29/2008

instead of using the query to sort by years, i want it to sort by months, how would i achieve this?


I think you do not have any OOB keywords for this. Below is what you can try:

  1. Get the datatable from the list
  2. Add a new column called "MONTH" to datatable
  3. Populate this column's value for each row in datatable with something like below
    FOREACH (Datarow DR in DT.Rows)
    DR["MONTH"] = DateTime.Parse(DR["DATECOLUNM"].ToString()).ToString("MM");
  4. Then create a dataview with sort based on column "MONTH"
  5. Finally use the dataview for binding it to your control


When you try to sort the dates i believe what you are expecting can't be achieved. When sorting is applied it would do it based on the years months and dates only. Any specific reason why you need this kind of sorting ?

  • 1
    Check the other answer out dude, it will show you how this sort of thing is done. – Hugh Wood Nov 20 '12 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.