简体   繁体   中英

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'

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.

sequelize.and(
  {id: '111'},
  sequelize.where(
    sequelize.fn('date', sequelize.col('event_date')), 
    '<=', '2016-10-10'
  )
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM