How To Sort Dates Below 1970 In JavaScript?
so I am sorting dates and there is one date of 1967-08-07, what would be the correct approach to it? The unix timestamp is negative and I haven't found any clues how to do in JS.
Solution 1:
The ISO 8601
1967-08-07
structure is easy sortable as string, because it has the year as first part, followed by month and day.
Solution 2:
If the dates are of different formats that are not easily compared, you could convert the dates to date objects and compare those:
// CREATE OBJECTS
var dateOne = new Date("October 16, 2017");
var dateTwo = new Date("1967-08-07");
// COMPARE
if(dateOne > dateTwo){
// DO SOMETHING
}
Post a Comment for "How To Sort Dates Below 1970 In JavaScript?"