Can't find records in Waterline by date/time

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 13:28:29

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. You can keep your code exactly as it is, but change the first line to:

var _date = new Date(moment().format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z');

Then your query should find all Games that start in the future.

Of course since your code is just returning current date, you don't really need moment at all:

var _date = new Date();

will work just as well.

var _date = moment().format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z';

you need to convert above string variable to date variable using below line

var tempDate = new Date(_date);

Now use $gte instead of '>='

Game.find({
    where:{
        active: true,
        start: {
            $gte : tempDate 
        }
    },
    limit: 1,
    sort: 'start asc'
}, function(err, game) {
    console.log('ERROR: ' + err);
    console.log('Game OBJ' + game.toString());
});

You can also use $gt, $lt, $lte.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!