2

In Express framework I am using Sequelize. I want select user's first name and last who are registered a specific date match with createdAt field. My query is in below.

const userData = models.users;
var querystring = { where: {createdAt: {[op.like]: '%2018-09-27%'}}, attributes: ['first_name', 'last_name'] }
userData.findOne(querystring).then(function (userData) {

    console.log(userData);

});

But I got error below....

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info. Arguments: [0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: %2018-09-27%, _f: undefined, _strict: undefined, _locale: [object Object]

Thanks in advance

1 Answer 1

2

You can use the date range query who are registered on a date.

use startTime = start of the day, endTime = end of the Day.

Model.findAll({
    where: {
        createdAt: {
            $gt: startTime,
            $lt: endTime
        }
    }
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.