[英]Query by date with column that is a datetime
How can I query for all records of a certain date if the column is a datetime?如果列是日期时间,如何查询特定日期的所有记录?
This doesn't work.这是行不通的。 Is there a preferred way to do this in sequelize?在 sequelize 中有更好的方法吗?
startDate
and endDate
are datetime
's startDate
和endDate
是datetime
的
Thing.findAll({
where: {
startDate = {
[Op.gte]: '02-20-2020'
},
endDate = {
[Op.lte]: '02-20-2020'
},
}
});
Split them and create a javascript Date object before using that straight in the query parameters.拆分它们并创建一个 javascript 日期 object,然后直接在查询参数中使用它。
const [month, day, year] = '02-20-2020'.split('-')
const date = new Date(year, month, day)
Thing.findAll({
where: {
startDate = {
[Op.gte]: date
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.