Between Dates Using Waterline ORM SailsJS

Purpose: to return a list of items created between two dates.

In accordance with this question https://github.com/balderdashy/waterline/issues/110between there is no function yet. However, the work around is as follows:

User.find({
    date: { '>': new Date('2/4/2014'), '<': new Date('2/7/2014') }
}).exec(/* ... */);

To be more precise, we do not want hardcoded dates to be higher, so we read the input from the form view as follows:

    start = new Date(req.param('yearStart') + '/' + req.param('monthStart') + '/' + req.param('dayStart'));
    end = new Date(req.param('yearEnd') + '/' + req.param('monthEnd') + '/' + req.param('dayEnd'));

Printing startand endthe console shows me this (for some reason, different time zones)?

from: Sat Mar 01 2014 00:00:00 GMT-0500 (EST)
to: Sat Apr 30 2016 00:00:00 GMT-0400 (EDT)

However, my view does not return anything every time.

+4
source share
2 answers

, , date createdAt .

, :

User.find({
    createdAt: { '>': start, '<': end }
}).exec(/* ... */);
+6

, API, toISOString() Date. : http://localhost:1337/:model/?where={date: {'<=', date.toISOString()}}

0

All Articles