user15557745
user15557745

Reputation: 149

Sequelize not creating right query with dates

I don't know, why sequelize changing the dates which I passed in arguments while creating a query?

Database => mysql

I mean that I write following query with sequelize:

Stock.findAll({
        where: {
            createdAt: {
                [Op.between]: ['2021-05-01 00:00:00', '2021-05-27 00:00:00'],
            },
        },
    })
        .then((resp) => {
            console.log(JSON.parse(JSON.stringify(resp)))
        })
        .catch((err) => console.error(err))

And sequelize creating this query -

SELECT `id`
     , `quantity`
     , `event`
     , `eventId`
     , `createdAt`
     , `updatedAt`
     , `stockItemId` 
  FROM `stocks` AS `stocks` 
 WHERE `stocks`.`createdAt` BETWEEN '2021-04-30 18:30:00' AND '2021-05-26 18:30:00';

Why sequelize changing 2021-05-01 00:00:00 to 2021-04-30 18:30:00 and 2021-05-27 00:00:00 to 2021-05-26 18:30:00?

Upvotes: 0

Views: 571

Answers (1)

restlessmodem
restlessmodem

Reputation: 448

This happens because you have to configure the correct timezone sequelize uses to write to the database. When you initialize the configuration add e.g.

timezone: '+05:30'

Upvotes: 1

Related Questions