Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Count records for each day between the startdate and enddate in sequelize ORM (Performing this query in nodejs)

I am passing start_time and end_time as a query parameter in an API and want to have count of the records on each day from start_time and end_time.
It is giving me total count of records between the specified start and end_time but I want count for each day individually.
Example start_time: 2017-10-07 and end_time is 2017-10-10
So, I want count for the number of records on the date: 2017-10-07, 2017-10-08, 2017-10-09 and 2017-10-10.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You want a GROUP BY clause in your sql to group your count by days. Here’s documentation on how to do that with Sequelize.
https://sequelize.org/master/manual/model-querying-basics.html#grouping

And if your date isn’t just a single day, but has hours and minutes, you might need to do some date truncation in your group by. Here’s some info on that:
Sequelize grouping by date, disregarding hours/minutes/seconds

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading