[英]Query by date with column that is a datetime
如果列是日期時間,如何查詢特定日期的所有記錄?
這是行不通的。 在 sequelize 中有更好的方法嗎?
startDate
和endDate
是datetime
的
Thing.findAll({
where: {
startDate = {
[Op.gte]: '02-20-2020'
},
endDate = {
[Op.lte]: '02-20-2020'
},
}
});
拆分它們並創建一個 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.