我是sequelize的新手,我不知道如何获取createdAt列的记录与当前日期的时间少于1小时,这是我的代码:
models.Trip.findAll({
where: {
createdAt: {
$gt: -------> createdAt <= 1 hour with current date
}
},
include: [
models.User,
models.Vehicle,
],
})
请问该怎么做,请帮帮我。谢谢!
最佳答案
使用sequelize.literal()
根据数据库服务器时间进行查询。
使用服务器:
created_at: {
[Op.gt]: sequelize.literal("NOW() - INTERVAL '24 HOURS'")),
}
通过从 Date.now()
中减去毫秒,使用设置为过去一小时的 Date
对象。
created_at: {
[Op.gt]: new Date(Date.now() - (60 * 60 * 1000)),
},
使用旧样式 operator aliases :
created_at: {
$gt: new Date(Date.now() - (60 * 60 * 1000)),
},
关于javascript - Sequelize : How to get record with createdat greater than 1 hour,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52453374/