Sequelize how to format sequelize.literal(‘CURRENT_TIMESTAMP’) in a query?

I’ve been trying to compare a date (yyyy-mm-dd) to sequelize.literal('CURRENT_TIMESTAMP') as shown below:

dataagendado: {
    [Op.gte]: sequelize.literal('CURRENT_TIMESTAMP')

This works for greater than cases but not when the value of dataagendado is equal to today’s date. I believe I need to format the CURRENT_TIMESTAMP data. I’ve been trying to find an answer but all I get are formatting for when a column is created, which doesn’t seem to be applicable inside a SELECT query. I’ve also tried sequelize.fn('NOW') and formatting it but got no luck.

Am I even on the right track? Any help would be greatly appreciated.


Disclaimer: I’m assuming you are using Postgres as the underlying database. If it’s not the case, please post your database engine.

You are using sequelize.literal('CURRENT_TIMESTAMP') which resolves in Postgres to NOW(). The NOW() function returns the timestamp with the current time. If you are comparing your date without the timestamp against a date with a timestamp that shouldn’t work.

You could use something like this:

dataagendado: {
    [Op.gte]: sequelize.literal('now()::Date')

In SQL the following happens:

SELECT NOW() => 2021-03-31T07:39:24.518Z

SELECT NOW()::Date => 2021-03-31T00:00:00.000Z