Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert datetime to date of a column in where condition using sequelize

Okay,

I want to convert column datetime to date while querying.

Can anyone help me out with sequelize query of below given query ?

select * from ev_events where DATE(event_date) <= '2016-10-10'
like image 542
Keyur Sakaria Avatar asked Jun 09 '16 10:06

Keyur Sakaria


People also ask

How do you get the current Date in Sequelize?

const TODAY = new Date(); const SUM = await OrdersModel. sum('price', { where: { created: Sequelize. DATE(TODAY), }, }); console. log(SUM);

How do you use greater than in Sequelize?

$gt stands for "greater than". You could use $gte instead of $gt . $gte stands for "greater than or equal to".


1 Answers

You can use sequelize.fn:

Event.findAll({
  where: sequelize.where(sequelize.fn('date', sequelize.col('event_date')), '<=', '2016-10-10')
})

I've had to guess how you have defined your model.

like image 176
MrWillihog Avatar answered Sep 17 '22 18:09

MrWillihog