Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

sql - SEQUELIZE - Invalid Value For Date

My sequelize WHERE condition looks like this:

 where: {
    [Op.and]: opAnd,
    [Op.gte]: [{order_date: moment(new Date(req.body.orderDateRange.trim().split("-")[0])).format("YYYY-MM-DD"), order_signing_date: moment(new Date(req.body.signingDateRange.split("-")[0])).format("YYYY-MM-DD")}],
    [Op.lte]: [{order_date: moment(new Date(req.body.orderDateRange.trim().split("-")[1])).format("YYYY-MM-DD"), order_signing_date: moment(new Date(req.body.signingDateRange.split("-")[1])).format("YYYY-MM-DD")}],
}

but it keeps returning an "Invalid Value" error at whatever date I throw at it:

Error: Invalid value { order_date: '2015-12-01', order_signing_date: '2020-12-09' }

I am running PostgreSQL on my backend. My order date is coming as a range, for example, "12/01/2000 - 12/01/2020". From the split, it is taking the first date and searching for order dates greater than or equal to it, and taking the second date and searching for order dates less than or equal to it.

I also tried this combination, but it still spits the same error (Side question: Which format is the correct one?):

 where: {
    [Op.and]: opAnd,
    [Op.and]: [{[Op.gte]:{order_date: moment(new Date(req.body.orderDateRange.trim().split("-")[0])).format("YYYY-MM-DD"), order_signing_date: moment(new Date(req.body.signingDateRange.split("-")[0])).format("YYYY-MM-DD")}}],
    [Op.and]: [{[Op.gte]:{order_date: moment(new Date(req.body.orderDateRange.trim().split("-")[1])).format("YYYY-MM-DD"), order_signing_date: moment(new Date(req.body.signingDateRange.split("-")[1])).format("YYYY-MM-DD")}}],
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...