WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Sort dates by year

[Resolved] Sort dates by year

  • We’re trying to figure out how to sort dates in this format – MM/DD/YEAR. We’ve tried a number of supposed solutions, but nothing worked.

    By default, these numbers are sorted by the month. We’re using TP as an event calendar, so in that scenario, the 2013 dates get mixed in with the 2014 dates. So 01/01/2014 comes before 02/01/2013 in the sorted results.

    Can you tell us how we can get this working so it sorts by year, then month, then day in the MM/DD/YEAR format?

    http://wordpress.org/extend/plugins/tablepress/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author TobiasBg

    @tobiasbg

    Hi,

    thanks for your post, and sorry for the trouble.

    To achieve that, please install this TablePress Extension: http://tablepress.org/extensions/datatables-sorting-plugins/
    That contains a sorting algorithm for the date format that you are using.
    If it doesn’t work out of the box, after installing this, we might need a small extra command. To find out how that has to look like, please post the link to the page with the table then.

    Another important thing: For the sort to work correctly, all cells in that Date column need to be dates.

    Regards,
    Tobias

    That could be the problem – we tried this extension, but some of the cells in that column were blank or said anytime. That would cause it not to sort properly then?

    Plugin Author TobiasBg

    @tobiasbg

    Hi,

    correct, “anytime” is recognized as a string, so that the sorting is thrown off. It might be possible to still force a certain sort type, but for that I’d need to see the table, so that I can tell you the necessary command to achieve this. Can you please post a link?

    Regards,
    Tobias

    Sorry, here you go:

    Training Calendar

    Plugin Author TobiasBg

    @tobiasbg

    Hi,

    thanks for the link!

    The necessary command for this would be

    "aoColumnDefs": [ { "sType": "date", "aTargets": [ 1 ] }, { "sType": "formatted-num", "aTargets": [ 4 ] } ]

    which is actually pretty close to what you already have. Please replace the current content of the “Custom Commands” textfield with that.
    I’ve also added code to fix the currency sorting in the fifth column to this command. (This is the reason why the Sorting Plugins Extension is necessary. It’s not necessary for the date sorting, as you are using MM/DD/YYYY, but only for the currency sorting.)

    Regards,
    Tobias

    Looks like we’ve got it. Thanks!

    Plugin Author TobiasBg

    @tobiasbg

    Hi,

    great! 🙂 Thanks for the confirmation!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] Sort dates by year’ is closed to new replies.