I have Product Model That Have Two Columns startDate and duration
The startDate it's the datetime are products supposed to show up
And duration is the showing time per day,
This is the code I have written
const dateTimeNow = new Date()
const productData = await productModel.findAll({
where: {
startDate: { [Op.gte]: dateTimeNow }, // StartDate >= dateTimeNow
},
what I want Is : find all products where startDate >= date.now() & startDate + duration <= date.now()
how can I do that in sequelize?
From the Sequelize doc, you can use
const Op = Sequelize.Op;
// startDate and endDate are Date objects
const where = {
startDate: {
[Op.between]: [startDate, endDate]
}
};
NOTE: between is inclusive that means (startDate <= from AND from <= endDate)
Learn more on operators in the doc http://docs.sequelizejs.com/en/latest/docs/querying/#operators