How to compare only dates in Sequelize?

Asked

Viewed 54 times

1

I am using ORM Sequelize and would like to compare only one date instead of the date with time.

I have the following date: 2021-05-06 03:00:00.0000000 +00:00

And I’m doing like this:

const dataAtual = new Date()
const lista = await myRepository.findAll({
  where: {
    dt_end: {[Op.lt]: dataAtual }
  }
});

I’d like to compare

SELECT *
  FROM tabela
WHERE dt_end < '2021-05-06'

I am using SQL Server

How can I compare only the date: 2021-05-06 and discard the rest?

1 answer

2


You can use the sequelize.fn to convert a datetime for date.

sequelize.fn("date", myRepository.dt_end);

The function will convert the 2021-05-06 03:00:00.0000000 +00:00 for 2021-05-06.

Take a look at this question here.

  • Thanks, I got an idea!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.