about datetime sorting

about datetime sorting

yu yen kanyu yen kan Posts: 65Questions: 31Answers: 0

I am using $.fn.dataTable.moment('YYYY MMMM DD HH:mm:ss'); in code to sort the datetime and my datetime output is 2017 February 28 23:19.

the result is something wrong, when ascending it sort to
2017 February 28 23:19
2017 July 27 19:12
2017 March 20 05:01

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Check your usage of moment formatting. It looks like 'MMMM' means show the month in words, so you end up sorting a string.

  • allanallan Posts: 63,480Questions: 1Answers: 10,467 Site admin

    You have :ss in your string format, but no seconds in your data - hence it won't work.

    Allan

  • yu yen kanyu yen kan Posts: 65Questions: 31Answers: 0

    what if I have multiple datatime field with different format? how can I do it with that?

  • allanallan Posts: 63,480Questions: 1Answers: 10,467 Site admin

    With that plug-in you simply define each format and it will automatically find it:

    $.fn.dataTable.moment('YYYY MMMM DD HH:mm:ss');
    $.fn.dataTable.moment('YYYY MMMM DD');
    

    Allan

This discussion has been closed.