无法按日期/时间在“水线"中找到记录 [英] Can't find records in Waterline by date/time

查看:70
本文介绍了无法按日期/时间在“水线"中找到记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在sails.js模型中比较日期时间?这就是我所做的,但是没有运气.

how compare a datetime in sails.js Model? here it is what i did but without luck.

var _date = moment().format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z';
Game.find({
    where:{
        active: true,
        start: {
            '>=' : _date
        }
    },
    limit: 1,
    sort: 'start asc'
}, function(err, game) {
    console.log('ERROR: ' + err);
    console.log('Game OBJ' + game.toString());
});

推荐答案

datetime类型在水线"(Sails ORM)中转换为实际的Javascript日期.因此,需要将其与日期对象而不是字符串进行比较.您可以将代码保持原样,但将第一行更改为:

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');

然后您的查询应找到将来开始的所有Game.

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

当然,由于您的代码仅返回当前日期,因此您根本不需要moment:

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

var _date = new Date();

同样适用.

这篇关于无法按日期/时间在“水线"中找到记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆