Jeff Robert Dagala
Jeff Robert Dagala

Reputation: 633

Sails.js could not get newly created user using date range query parameter

I do have problem with Sails.js using sails-disk as database, when I get the user with this query parameter

// Assuming that the current date is end_date

var end_date="2014-06-06T15:59:59.000Z"

var start_date="2014-06-02T16:00:00.000Z"

    User.find().where({
       createdAt: { 
           '>=': start_date,
            '<=' : end_date
       }
    }).exec(function(err, users) {

    });

I could not get the newly created user, but when I do restart my sails js app, I could now get the newly created user within the date range that I provided

Upvotes: 0

Views: 690

Answers (1)

sgress454
sgress454

Reputation: 24948

The datetime type is transformed into an actual Javascript date in Waterline (the Sails ORM). So it needs to be compared against a date object, not a string. If you change your query to:

User.find().where({
   createdAt: { 
       '>=': new Date(start_date),
       '<=' : new Date(end_date)
   }
})

it should work.

Upvotes: 1

Related Questions