I have an array with this format. I just want to pull the 1 oldest date.
This is value in array looks like:
Array:
creationDate = ['Wed Feb 13 21:14:55 GMT 2019','Wed Feb 13 21:19:42 GMT 2019','Wed Feb 13 21:28:29 GMT 2019','Wed Feb 13 21:31:04 GMT 2019'];
This is my code:
Code:
// this below code is not working as expected
if(creationDate){
var orderedDates = creationDate.sort(function(a,b){
return Date.parse(a) > Date.parse(b);
});
}
Expected Result:
Wed Feb 13 21:14:55 GMT 2019
Date.parse(a) - Date.parse(b)(or switch a and b to sort in the opposite order). The compare function expects a number to be returned rather than a boolean. Check rules for thee compare function here: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…