Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9218543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:53:20+00:00 2026-06-18T02:53:20+00:00

I saw this Count records created within the last 7 days but still need

  • 0

I saw this Count records created within the last 7 days but still need some help in getting the syntax of COUNT right, right now I have

@count_users = User.count('comment')

which gives me Count of all comments but I need to know count of all comments made only in last 7 days or in last 1 month, but I am not able to figure out the correct syntax for it

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:53:21+00:00Added an answer on June 18, 2026 at 2:53 am

    This count:

    @count_users = User.count('comment')
    

    Generates the following SQL:

    SELECT COUNT(comment) FROM "users"
    

    So unless you have a comment column in your users table, it is not counting the right objects.

    If you have a Comment model, you can use the following to count all comments created in the past 7 days:

    Comment.where('created_at >= ?', Time.zone.now - 7.days).count # count for a week
    Comment.where('created_at >= ?', Time.zone.now - 1.months).count # count for a month
    

    If you want to count the Comments of a specific User, you can use this (assuming a Comment belongs_to a User and a User has_many Comments):

    Comment.where(user_id: user.i).where('created_at >= ?', Time.zone.now - 7.days).count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw some code in TCL like this: namespace eval ::info { set count
I'm getting the above error. I saw other similar posts on this error but
I saw this topic and implement IntentService as describes, but what if I want
Saw this: Can you use index in mysql using "col1 OR col2"? but thought
i saw some online flash games can do this: when you switch your current
I did a search, but nothing I saw was the same or could help.
I saw this Stack Overflow Question but I cannot find the answer to the
While reading tutorial for wxWiidgets I saw this Tutorial where author has created 2
http://lxr.linux.no/linux+v2.6.35/include/linux/preempt.h#L21 I am just trying get the linux source. I saw this preempt count
I saw this How to count the number of files in a directory using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.