dd-MON-yyyy date format
dd-MON-yyyy date format
Ive been trying to add a date sorting function that will sort 12-May-2010 or 12-May-10.
here is what i have come up with so far, which is not working at all.. any help is appreciated
[code]
jQuery.fn.dataTableExt.oSort['shortdate-desc'] = function(x) {
var months = {};
months["JAN"] = "01";
months["FEB"] = "02";
months["MAR"] = "03";
months["APR"] = "04";
months["MAY"] = "05";
months["JUN"] = "06";
months["JUL"] = "07";
months["AUG"] = "08";
months["SEP"] = "09";
months["OCT"] = "10";
months["NOV"] = "11";
months["DEC"] = "12";
var x = x+''; //Make sure it's a string
var hit = x.match(/(\d{2})-([A-Za-z]{3})-(\d{2,4})/);
if (hit && hit.length == 4) {
return hit[3] + months[hit[2].toUpperCase()] + hit[1];
}else{
return x;
}
};
[/code]
here is what i have come up with so far, which is not working at all.. any help is appreciated
[code]
jQuery.fn.dataTableExt.oSort['shortdate-desc'] = function(x) {
var months = {};
months["JAN"] = "01";
months["FEB"] = "02";
months["MAR"] = "03";
months["APR"] = "04";
months["MAY"] = "05";
months["JUN"] = "06";
months["JUL"] = "07";
months["AUG"] = "08";
months["SEP"] = "09";
months["OCT"] = "10";
months["NOV"] = "11";
months["DEC"] = "12";
var x = x+''; //Make sure it's a string
var hit = x.match(/(\d{2})-([A-Za-z]{3})-(\d{2,4})/);
if (hit && hit.length == 4) {
return hit[3] + months[hit[2].toUpperCase()] + hit[1];
}else{
return x;
}
};
[/code]
This discussion has been closed.
Replies
[code]
jQuery.fn.dataTableExt.oSort['shortdate-asc'] = function(x,y) {
var months = {};
months["JAN"] = "01";
months["FEB"] = "02";
months["MAR"] = "03";
months["APR"] = "04";
months["MAY"] = "05";
months["JUN"] = "06";
months["JUL"] = "07";
months["AUG"] = "08";
months["SEP"] = "09";
months["OCT"] = "10";
months["NOV"] = "11";
months["DEC"] = "12";
x = (x=="")? 0 : x.split('-');
y = (y=="")? 0 : y.split('-');
if(x.length){
x = x[2] + months[x[1].toUpperCase()] + x[0];
}
if(y.length){
y = y[2] + months[y[1].toUpperCase()] + y[0];
}
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['shortdate-desc'] = function(x,y) {
var months = {};
months["JAN"] = "01";
months["FEB"] = "02";
months["MAR"] = "03";
months["APR"] = "04";
months["MAY"] = "05";
months["JUN"] = "06";
months["JUL"] = "07";
months["AUG"] = "08";
months["SEP"] = "09";
months["OCT"] = "10";
months["NOV"] = "11";
months["DEC"] = "12";
x = (x=="")? 0 : x.split('-');
y = (y=="")? 0 : y.split('-');
if(x.length){
x = x[2] + months[x[1].toUpperCase()] + x[0];
}
if(y.length){
y = y[2] + months[y[1].toUpperCase()] + y[0];
}
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]