Regular date sort mm/dd/yyyy

Regular date sort mm/dd/yyyy

verlagerverlager Posts: 18Questions: 3Answers: 0
edited March 2011 in General
My url is http://communitychessclub.com/bestgames.php

The date column is mm/dd/yyyy and I need to sort it by year+month+day. I have done a forum "sort date" search and, as I lack a CS degree, it is quite difficult for me to understand. It seems strange that the user (me, an amateur webmaster) is required to do programming to get dates to sort in dataTables, rather than the developer (you, a jquery and js professional). I would have expected date sort to be built-in.

If you solve this problem satisfactorily (so I can understand it) I will contribute financially. I think you deserve it!

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Hi verlager,

    Date sorting is indeed built=in to DataTables - anything which Javascript's built in Date.parse() finds as a date will be automatically date sorted. However, there is a limited range of date expressions that will work with Date.parse(). For that there are the sorting plug-ins: http://datatables.net/plug-ins/sorting - which can be customised to any format.

    However, looking at your site, the date column does seem to work correctly for me (Safari 5). Is it not sorting correctly for you? What browser are you using - there are some differences between the automatically detected date formatted in the browsers, but I would have thought the standard US date representation would have been picked up by all.

    Allan
  • verlagerverlager Posts: 18Questions: 3Answers: 0
    Well I used php to change the date mm/dd/yyyy to yyyy/mm/dd because I needed a fix on the spot. I will change it back to illustrate the difficulty I am experiencing. It sorts like this: 11/22/3333

    Please check http://communitychessclub.com/games-nu.php and verify this for yourself.
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Thanks for changing it back - it problem is that you have invalid dates in the date column - for example "00/00/1985". These can't be parsed as dates and therefore DataTables doesn't treat the column as having a date type for sorting.

    Allan
  • verlagerverlager Posts: 18Questions: 3Answers: 0
    Thanks! Your solution worked perfectly. Expect a gift soon (now).
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    :-) Thanks very much - and good to hear that did the job!

    Regards,
    Allan
This discussion has been closed.