I am new in sequelize, and I don't know how to get the records with createdAt column less than 1 hours with the current date and here is my code :
models.Trip.findAll({
    where: {
      createdAt: {
        $gt:  -------> createdAt <= 1 hour with current date
      }
    },
    include: [
      models.User,
      models.Vehicle,
    ],
  })
How to do that, please help me. Thanks!
Use sequelize.literal() to query based on the database server time.
Using the server:
created_at: {
  [Op.gt]: sequelize.literal("NOW() - INTERVAL '24 HOURS'")),
}
Use a Date object set to one hour in the past by subtracting milliseconds from Date.now().
Using Sequelize.Op
created_at: {
  [Op.gt]: new Date(Date.now() - (60 * 60 * 1000)),
},
Using old style operator aliases:
created_at: {
  $gt: new Date(Date.now() - (60 * 60 * 1000)),
},
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With