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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:55:56+00:00 2026-06-15T23:55:56+00:00

I have to show how many api calls made a user during each day

  • 0

I have to show how many api calls made a user during each day for the last 30 days, in order to build a nice graph. I didn’t have any problem so far with that. Something important to notice is that the database and system timezone is in UTC, but most of the users are located in Pacific Time (GMT -8).

In order to get the api usage grouped by the day of use, I can do something like

ApiCall.
  where(user_id: @user.id).
  where("requested_at > ?", Time.zone.now.to_date - 30.days).
  group("date(requested_at)").
  select("count(*) as qty, date(requested_at) as requested_at").all

Now the problem, is that the time for a user located in California, is far different from the time for a user located in England and that’s where I’m failing.

A user makes an API Call, located in California, on 2012-12-14 21:00:00 GMT -8. The API CALL in the DB is stored with the time 2012-12-14 05:00:00 (because its in GMT, so it add 8 hours).

Now for that user, if I go to see my daily usage, with the query I did, it will show that my api call was not made on 2012-12-14 at 21:00:00, because on the database its stored as 2012-12-14 05:00:00, and for the user the api usage will show that he did that api call on the next day, and he will think that the system is not working fine.

So in few words, how can I group the api calls based on the user timezone and not based on the database timezone?

  • 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-15T23:55:57+00:00Added an answer on June 15, 2026 at 11:55 pm

    Yes there is, by using mysql convert timezone function, its not a nice solution yet it works

    ApiCall.
      where(user_id: @user.id).
      where("requested_at > ?", Time.zone.now.to_date - 30.days).
      group("date(convert_tz(requested_at, '+00:00', '-08:00'))").
      select("count(*) as qty, date(requested_at) as requested_at").all
    

    I’ll add a bounty later to see if someone can tell me about a better solution to these kind of reports with rails and timezones

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

Sidebar

Related Questions

I have looked at many other threads that show how to use accelerometer values,
I have a table with many rows of data, and I want to show
I have a page with many tooltips. I want to show/hide every one seperatly
I have three models. User, Product, and Season. I used a standard has many
so i have a little tricky combination here Company has many Users User belongs
I have an app that making API requests to the last.fm website using the
I have a grid of many images and each image has a CSS class
Hi on our dev environment we have show all errors, warnings and notices. I'm
I have some text in a UITextView, that I would like to have show
I have to show slideshow of images. But at one moment I know only

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.