Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do you group by week for a month of records, but only find dates for the month.

Darion Wood asked in Rails

arget_date = Date.today.beginning_of_month
target_range = target_date..target_date.end_of_month

Post.where(created_at: target_range).group_by_week(:created_at, range: target_range).sum(:view_count)
I'm using group_by_week() that is included with groupdate gem. The issue is, its returning records from the end of the last month for certain months. Given that certain months begin on Wednesday. I would like to get all record for example: The month of July 1st-31st and then get the sums for each week within the month. Week 1, should start on July 1st.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,796+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.