Date time with am pm sorting with moment not working with no leading day digit
Date time with am pm sorting with moment not working with no leading day digit
![lancew](https://secure.gravatar.com/avatar/44e5ea01f8352e08ca3f8e1102d2e9dd/?default=https%3A%2F%2Fvanillicon.com%2F44e5ea01f8352e08ca3f8e1102d2e9dd_200.png&rating=g&size=120)
I have dates I am trying to sort but it looks like 1 digit days are treated differently than 2 digit days.
Here is an example of how the dates are sorting.
Here is the moment setup I am using.
$.fn.dataTable.moment('M/d/yyyy hh:mm:ss A');
I also tried, $.fn.dataTable.moment('MM/dd/yyyy hh:mm:ss A');
They both seem to work the same way which is not correct.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The Moment.js documentation shows that
D
should be used for day of the month - notd
.Try:
Allan
That works great. Thanks!
I have tried the same fix given by Allan, but its not working for me. Issue is the same. It sorts dates with 2 digit days properly, but when it comes to single digit days, it considers 2 as 20 instead of 02 and is sorting it that way. Any other solution?
It works here:
http://live.datatables.net/juqapuzo/1/edit
Did you load the moment.js and datetime-moment.js?
Does you date time format match the format specified in this:
$.fn.dataTable.moment( 'M/D/YYYY h:mm:ss A');
EDIT: If your format doesn't match 'M/D/YYYY h:mm:ss A' then you will need to change it per the moment.js docs to match. It needs to match exactly, not just the
D
.Maybe you can update my example with an example using your datetime data/
Kevin