Search code examples
javascriptmomentjslinq.js

order a collection of momentjs dates by the current date with linq.js


I want to sort in ascending order a collection of momentjs date objects.

The problem is that moment.date() returns the day of the month number.

How can I sort this by the real date? and still returning momentjs dates from the query?

var meetingsOrdered = Enumerable.from(meetings).orderBy("$.meetingDate.date()").toArray();

Solution

  • date() returns the day of the month of the date. Moment instances are directly comparable so you don't need to do much more.

    var meetingsOrdered = Enumerable.from(meetings)
        .orderBy("$.meetingDate")
        .toArray();