Home > Mobile >  Count records for each day between the startdate and enddate in sequelize ORM (Performing this query
Count records for each day between the startdate and enddate in sequelize ORM (Performing this query

Time:03-11

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.

CodePudding user response:

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

  • Related