Categories
JavaScript Answers

How to run where statement with date with Sequelize?

Spread the love

Sometimes, we want to run where statement with date with Sequelize.

In this article, we’ll look at how to run where statement with date with Sequelize.

How to run where statement with date with Sequelize?

To run where statement with date with Sequelize, we use Op properties to form the query.

For instance, we write

const { Op } = require("sequelize");

model.findAll({
  where: {
    start_datetime: {
      [Op.gte]: moment().subtract(7, "days").toDate(),
    },
  },
});

to call findAll with an object to query for entries with start_datetime bigger than or equal to 7 days ago.

Op.gte is greater than or equal to.

Conclusion

To run where statement with date with Sequelize, we use Op properties to form the query.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *