I have an array with date time stamp. The format is eg. 11/6/2015 15-47-35.501
I have to get the maximum/ latest DateTime stamp from this array. So applied the logic of sorting but not working. And I have to take this format only otherwise previous records will not work If I take other formats.
Code snippet is
function somefunction()
{
var creation_dt_newarr = ["11/6/2015 15-47-35.501","11/6/2015 16-19-32.939","11/6/2015 18-31-31.343"]
creation_dt_newarr = creation_dt_arr.sort(sortFunction);
var replaced_data = creation_dt_newarr[creation_dt_newarr.length-1];
var max_creation_dt_res = replaced_data;
}
function sortFunction(a,b){
var dateA = new Date(a).getTime();
var dateB = new Date(b).getTime();
return dateA > dateB ? 1 : -1;
};
Please help me out how this will work. Thanks in advance.
This could help: