在日期之间使用 Waterline ORM SailsJS [英] Between Dates using Waterline ORM SailsJS

查看:39
本文介绍了在日期之间使用 Waterline ORM SailsJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:返回在两个日期之间创建的项目列表.

根据这个问题 https://github.com/balderdashy/waterline/issues/110 目前还没有 between 函数.但是,解决方法如下:

According to this issue https://github.com/balderdashy/waterline/issues/110 there is no between function just yet. However the work around is the following:

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

更准确地说,我们不想要上面的硬编码日期,因此我们从表单提交中读取输入,如下所示:

To be more exact, we don't want the hard coded dates above so we read in the input from a form submission like so:

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

startend 打印到控制台向我展示了这一点(由于某种原因不同的时区)?

Printing start and end to console shows me this (different timezones for some reason)?

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 returns nothing every time.

推荐答案

在写这个问题时,我意识到问题是我的过滤器中有 date 而不是 createdAt.

While writing this question I realized the issue was that I had date instead of createdAt in my filter.

所以以下工作:

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

这篇关于在日期之间使用 Waterline ORM SailsJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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