Sorting Date And Time With Am | Pm In Jquery
I have my javascript to sort date in ascending(that is, arrange from the newest). I am able to do for the dates, but i couldnt sort the time with AM or PM. I can do it in 24 hours
Solution 1:
you can use following code you need to fix date format first date1.replace("pm"," PM").replace("am"," AM")
before parsing it into date to compare it
functionsortAscending(a, b) {
var date1 = $(a).find("time").text();
var date2 = $(b).find("time").text();
date1 = Date.parse(date1.replace("pm"," PM").replace("am"," AM"));
date2 = Date.parse(date2.replace("pm"," PM").replace("am"," AM"));
returnnewDate(date1 > date2);
}
$(document).ready(function() {
$('#wrapper .cards').sort(sortAscending).appendTo('#wrapper');
});
output it will be
022012/04/2002:41am012012/04/2010:25am042012/04/2010:45am032012/04/2007:00pm
Post a Comment for "Sorting Date And Time With Am | Pm In Jquery"