0

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?

1 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.