Date (dd . mm[ . YYYY])

Sort dates in the format dd/mm/YY[YY] (with optional spaces)

  • Author: Robert SedovÅ¡ek
  • Deprecated: This plug-in has been deprecated and replaced with other functionality. Please see the detailed description below for more information.

Similar to the Date (dd/mm/YY) data sorting plug-in, this plug-in offers additional flexibility with support for spaces between the values and either . or / notation for the separators.

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-eu-pre": function ( date ) {
        date = date.replace(" ", "");
        
        if ( ! date ) {
            return 0;
        }

        var year;
        var eu_date = date.split(/[\.\-\/]/);

        /*year (optional)*/
        if ( eu_date[2] ) {
            year = eu_date[2];
        }
        else {
            year = 0;
        }

        /*month*/
        var month = eu_date[1];
        if ( month.length == 1 ) {
            month = 0+month;
        }

        /*day*/
        var day = eu_date[0];
        if ( day.length == 1 ) {
            day = 0+day;
        }

        return (year + month + day) * 1;
    },

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

    "date-eu-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-eu', targets: 0 }
     ]
  } );