Tomas Eglinskas
Tomas Eglinskas

Reputation: 855

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.

Upvotes: 1

Views: 132

Answers (2)

Tony
Tony

Reputation: 3068

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

}

Upvotes: 0

Nina Scholz
Nina Scholz

Reputation: 386680

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.

Upvotes: 6

Related Questions