Reputation: 5451
I'd like to make a query on dates using SequelizeJS but i don't know how to do and there is nothing on that on the website...
My code :
var day = request.params.day;
Appointment.findAll({where: ["start.day() = day"]}); // start is my column, format with DATETIME
Upvotes: 1
Views: 4075
Reputation: 7407
You can just use the regular comparison operator, as long as your date is in a valid format. For this purpose you can just create a Date
object out of the input, and then pass it to the Sequelize
query, like this:
var day = new Date(request.params.day);
Appointment.findAll({where: ['start > ?', day]}).then(function (result) {
// do stuff here
});
Upvotes: 1
Reputation: 28798
Depending on your DB there might be some function to extract the day from the column. Never seen the .day
syntax before though.
Appointment.findAll({
where: sequelize.where(sequelize.fn('day', sequelize.col('start')), day)
});
On latest master this should produce something like
WHERE DAY("start") = day
Upvotes: 1