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 7556817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:57:37+00:00 2026-05-30T11:57:37+00:00

I am trying to create a array that should be something like this: [

  • 0

I am trying to create a array that should be something like this:

[ [created_at date * 1000, count record for that date],
  [created_at date * 1000, count record for that date], 
  [created_at date * 1000, count record for that date] ]

The created_at date is not exactly the same, because of minutes, hours and seconds.
I was thinking is it possible to change created_at time on create to 00:00:00

I have tried with this,

@kliks = Klik.all.map{|klik| [(klik.created_at.to_i * 1000), 1]}

But I have not figure out to sum those records that are created the same day. Also this loops create a array for every single record, I don’t want duplicates of the sum.

  • 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-05-30T11:57:39+00:00Added an answer on May 30, 2026 at 11:57 am

    Rails has ActiveRecord::Calculations which is designed to do exactly this sort of thing at the database level. You should use it. In this case, count is the method you want:

    @kliks = Klik.count( :group => "DATE( created_at )" )
    

    This is equivalent to the following SQL:

    SELECT *, COUNT(*) FROM kliks
    GROUP BY DATE( created_at )
    

    The DATE() function is MySQL changes a datetime (like created_at, e.g. 2012-02-27 10:08:59) to a plain date (e.g. 2012-02-27). No need to go converting things to integers or multiplying minutes and seconds, and no need to use map or any other method in Ruby.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to create an extension that could slice any array-like class (since
I am trying to create an array or list that could handle in theory,
I'm trying to create an array of strings that can be randomized and limited
I am trying to create a UIImage from a byte array that is actually
I have a 3x3 array that I'm trying to create a pointer to and
I'm trying to create an array of structs and also a pointer to that
Im trying to create a method that take 2 int array as the input
I'm trying to create a function that would dynamically allocate an array, sets the
I'm trying to create a custom JSP tag that would take an array object
I'm getting very stuck on something that should be very easy. I am trying

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.