Search code examples
jqueryparsingdatetimetablesorter

jQuery tablesorter parser for datetime in DD.MM.YYYY HH:MI in 24hour format


I found this thread: jQuery tablesorter parser for datetime in MM.DD.YYYY HH:MI AM format

but i want to sort date times like so: 22/01/2012 23:43

how can this parser which is in AM/PM format be modified to do that:

ts.addParser({ id: "srsDate", is: function (s) { return /\d{1,2}\.\d{1,2}\.\d{1,4} \d{1,2}:\d{1,2}\s(am|pm)/.test(s); }, format: function (s) { return Date.parse(s); }, type: "numeric" });

or can this be done directly from the tablesorter by setting the dateFormat to something like:

$("table").tablesorter({
  theme : 'blue',
  dateFormat : "ddmmyyyy HH:mm", // set the default date format
}

Thanks in advance!


Solution

  • Sort UK/European date format dd/mm/yyyy hh:mm(works both with and without hour) by defining dateformat:"uk" like so:

    $("#tableName").tablesorter({dateFormat: "uk"});