Hey Yaara,
had the same issue, found a solution here:
https://datatables.net/plug-ins/sorting/datetime-moment
Basically, the default supported date format is YYYY/MM/DD. In order to support a DD/MM/YYYY format you’d have to load moment.js & datetime-moment.js . If you’re using WordPress, you can enqueue them by adding this snippet to your functions.php (just be sure to place the JS codes in the right folder):
wp_enqueue_script( 'moment', '/js/moment.js', array ( 'jquery' ), 1.1, true);
wp_enqueue_script( 'datetime', '/js/datetime-moment.js', array ( 'moment' ), 1.1, true);
Then specify the format you want to support like this:
jQuery(document).ready(function($) {
// needed for running jquery in a WordPress environment
$(document).ready(function() {
$.fn.dataTable.moment( 'DD/MM/YYYY' );
} );
});
Thread Starter
Yaara
(@yaaraher)
I tried what you suggested and it resulted in a corrupted functions.php 🙁
In wp_enqueue_script I tried several $src options but none of them worked (relative, full path, full url).
Is functions.php the right place?
Yikes! Sorry about that.
To avoid corrupting functions.php, try using a snippets plugin such as this one, which allows you to safely activate and deactivate pieces of code. Where did you put moment.js and datetime-moment.js? I put them in a “js” folder in my WP installation root directory, and it works fine.
And in case it wasn’t clear, the jQuery code should be called from a JavaScript file or added to the theme using a <script> tag, and NOT added as a snippet to functions.php… 🙂
Also, I stumbled upon another solution to the date format issue. Have a look at the “date-eu” type, it might be simpler.