Sequelize Where statement with date

前端 未结 4 1898
野的像风
野的像风 2020-12-14 14:01

I am using sequelize as my backend ORM. Now i wish to do some where operations on a Date.

More Speceficly i want to get all data where a date is from now and 7 days

4条回答
  •  有刺的猬
    2020-12-14 14:28

    You can also use Sequelize.literal() to perform dates manipulation in SQL.

    The following code works with Postgres, but I'm quite sure something similar could be done in other systems as well:

    model.findAll({
      where: {
        start_datetime: {
          $gte: Sequelize.literal('NOW() - INTERVAL "7d"'),
        }
      }
    })
    
    

提交回复
热议问题