0

i just using sequelize for a few months. This ORM is really fast and efficient. But now im facing a problem, i need to use date_add in my query to add hours in my data.

Here is my code

obd_data.gps_data_2020.findAll({
        attributes:[
            'car_id',
            [sequelize.fn('max',sequelize.fn('date_add',sequelize.col('collect_datetime'),'INTERVAL 7 HOUR')),'collect_datetime'],
            [sequelize.fn('timestampdiff',sequelize.literal('hour'),sequelize.col('collect_datetime'),sequelize.fn('now')),'off_time']
        ],
        group:['car_id'],
        order:[['car_id','desc']]
})

its completely fine with another mysql query function such a timediff, max, sum , etc. But for date_add, i have no clue why this cant be work. And i haven't found same problem in stackoverflow,

Please help master, Thanks!

2 Answers 2

1

In the end, i used seqeulize.literal() to use date_add mysql func haha, thanks guys

Sign up to request clarification or add additional context in comments.

Comments

0

I think you'll have to define a virtual field in your model to do that, date_add does not appear to be a sequelize function.... https://sequelize-guides.netlify.com/virtual-columns/.. This is a field that does not get persisted or anything, just created on a select type thing

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.