moment.js sorting 'MM/DD/YYYY h:mm:ss a' format not working

moment.js sorting 'MM/DD/YYYY h:mm:ss a' format not working

idris_bengaliidris_bengali Posts: 20Questions: 3Answers: 1

I created a milestone from an existing example and it is here http://live.datatables.net/juqapuzo/25/edit. have no issues with date only fields.

Thank you

Idris

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited December 2018 Answer ✓

    I commented out the moment plugin CDN and copied the code into the JS area. I added a couple of console.log commands and it highlights the issue. The problem is inconsistency with the format of your datetime string. In some cases you have to spaces between the date and the time and in others you have one. Looks like it depends on whether the hours is one digit or two.
    http://live.datatables.net/yeraheva/1/edit

    Note: I put two spaces in $.fn.dataTable.moment('MM/DD/YYYY h:mm:ss a'); to match the first rows that have two spaces.

    My suggestion would be to fix this inconsistency in your server code. However you could try replacing the two spaces with one using columns.render.

    Kevin

  • idris_bengaliidris_bengali Posts: 20Questions: 3Answers: 1

    Thank you KT... I fixed the program which does the HTML merge and it is working as expected.

    Do I have the ability to close this post?

    Idris

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

    I've marked Kevin's reply as an accepted answer.

    Allan

This discussion has been closed.