Categories
JavaScript Answers

How to add Where statement with date with Node Sequelize?

Spread the love

To add Where statement with date with Node Sequelize, we use operator properties.

For instance, we write

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

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

to call findAll to look for the entries with start_datetime bigger than or equal to 7 days before today.

We get the date with moment().subtract(7, "days").toDate().

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 *