I am using a Jquery plugin called datatables
Its fantastic, however I cannot get the dates to sort correctly according to the dd/mm/yyyy format.
I have looked at their support formats but none of these fixes seem to work.
Can anybody here help me please?
Try this plugin.
As stated here you need to include Moment.js and the datatable-moment plugin, then just declare the date format you are using. The plugin will autodetect your date columns and sort it like it should be. For moment.js format explanations, check here.
Example:
use this snippet!
the moment js works well for all date and time formats, add this snipper before you initialize the datatable like i've done earlier.
Also remember to load the http://momentjs.com/
What seems to work for me was
push the full datetime object fetched with a select query from my db in a dataset wich will be draw by datatable format "2018-01-05 08:45:56"
then
Rows get sorted right , then I get a html I want in the row
To the column you want ordering keep "sType": "date-uk" for example:-
"data": "OrderDate", "sType": "date-uk"
After the completion of Datatable script in ajax keep the below codeThen You will get date as 22-10-2018 in this format
An other solution : https://datatables.net/blog/2014-12-18
with 2 javascripts libs : //cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js and //cdn.datatables.net/plug-ins/1.10.15/sorting/datetime-moment.js
then only this :
If you get your dates from a database and do a for loop for each row and append it to a string to use in javascript to automagically populate datatables, it will need to look like this. Note that when using the hidden span trick, you need to account for the single digit numbers of the date like if its the 6th hour, you need to add a zero before it otherwise the span trick doesn't work in the sorting.. Example of code: