The jQuery TableSorter plugin comes with built-in support for two ISO date formats via RegEx:
Long such as: January 6, 1978 9:12 AM or Jan. 6, 2001 9:12 AM
^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$
Short such as: 1/6/78
\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}
Because I wanted to use the format of “Jan 6, 1978” I had to write my own parser. I could have just modified the default RegEx, but since I could guarantee the format of the input date, I could create a simpler RegEx:
// TableSort parser for date format: Jan 6, 1978
$.tablesorter.addParser({
id: 'monthDayYear',
is: function(s) {
return false;
},
format: function(s) {
var date = s.match(/^(\w{3})[ ](\d{1,2}),[ ](\d{4})$/);
var m = monthNames[date[1]];
var d = String(date[2]);
if (d.length == 1) {d = "0" + d;}
var y = date[3];
return '' + y + m + d;
},
type: 'numeric'
});
var monthNames = {};
monthNames["Jan"] = "01";
monthNames["Feb"] = "02";
monthNames["Mar"] = "03";
monthNames["Apr"] = "04";
monthNames["May"] = "05";
monthNames["Jun"] = "06";
monthNames["Jul"] = "07";
monthNames["Aug"] = "08";
monthNames["Sep"] = "09";
monthNames["Oct"] = "10";
monthNames["Nov"] = "11";
monthNames["Dec"] = "12";
This can be easily adapted for other date formats. To assist with testing with Firebug, place these two lines at the end of the “format” function to output input date and created string:
console.log(date);
console.log('' + y + m + d);
Enjoy.