Node Js 按月续写选择查询

Ram*_*h S 3 orm select node.js sequelize.js

我在新的Node Js,在我Node Js使用的项目时sequelize ORMMySql数据库。

这是我的查询,我想按月编写选择查询。

这是我的查询 SELECT * FROM cubbersclosure WHERE MONTH(fromDate) = '04'

这里的fromDate字段类型是date

在此处输入图片说明

这是我的代码:

var fromDate = '2019-04-01'
var fromDateMonth = new Date(fromDate);
var fromMonth = (fromDateMonth.getMonth()+ 1) < 10 ? '0' + (fromDateMonth.getMonth()+1) : (fromDateMonth.getMonth()+1);

CubbersClosure.findAll({
    where:{
        // select query with Month (04)... //fromMonth
    }
}).then(closureData=>{        
    res.send(closureData);
}).catch(error=>{
    res.status(403).send({status: 'error', resCode:200, msg:'Internal Server Error...!', data:error});
});
Run Code Online (Sandbox Code Playgroud)

这里fromMonth只获取日期的月份,所以我想按月编写代码选择查询。

kka*_*gil 5

我不确定,但试试这个怎么样?

where: {
  sequelize.where(sequelize.fn("month", sequelize.col("fromDate")), fromMonth)
}
Run Code Online (Sandbox Code Playgroud)