Date (dd/mm/YY)

Sort dates in the format dd/mm/YY

  • Author: Andy McMaster
  • Deprecated: This plug-in has been deprecated and replaced with other functionality. Please see the detailed description below for more information.

DataTables internal date sorting replies on Date.parse() which is part of the Javascript language, but you may wish to sort on dates which is doesn't recognise. The following is a plug-in for sorting dates in the format dd/mm/yy.

An automatic type detection plug-in is available for this sorting plug-in.

Please note that this plug-in is **deprecated*. The datetime plug-in provides enhanced functionality and flexibility.

Plug-in code

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    "date-uk-pre": function ( a ) {
        if (a == null || a == "") {
            return 0;
        }
        var ukDatea = a.split('/');
        return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
    },

    "date-uk-asc": function ( a, b ) {
        return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    },

    "date-uk-desc": function ( a, b ) {
        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
    }
} );

CDN

This plug-in is available on the DataTables CDN:

JS

Note that if you are using multiple plug-ins, it is beneficial in terms of performance to combine the plug-ins into a single file and host it on your own server, rather than making multiple requests to the DataTables CDN.

Version control

If you have any ideas for how this plug-in can be improved, or spot anything that is in error, it is available on GitHub and pull requests are very welcome!

Example

$('#example').dataTable( {
     columnDefs: [
       { type: 'date-uk', targets: 0 }
     ]
  } );