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

  • Home
  • SEARCH
  • 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 6187381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:02:54+00:00 2026-05-24T02:02:54+00:00

I have a problem with rails timezones. application.rb config.time_zone = ‘Athens’ controller @from =

  • 0

I have a problem with rails timezones.

application.rb

config.time_zone = 'Athens'

controller

@from = (Time.zone.now-1.day).to_date
@to = (Time.zone.now).to_date
Entry.where(:created_at => @from..@to)

This query supposed to list entries which were created yesterday. When i list entries, i see that some entries were created today.

For example:

It is 5:53 am now and i see that the last entry which was created yesterday was created 3 hours ago, it mustn’t be smaller than 6 hours. Any help will be appreciated.

  • 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-24T02:02:55+00:00Added an answer on May 24, 2026 at 2:02 am

    Your database is probably using UTC timestamps (at least it should be) but Time.zone.now is in your local timezone. Then you call to_date and lose the timezone information. Try this:

    @from = (Time.zone.now - 1.day).beginning_of_day.utc
    @to   = (Time.zone.now).beginning_of_day.utc
    Entry.where(:created_at => @from..@to)
    

    So you call beginning_of_day to get back to 00:00:00 and then convert to UTC with utc to get your timestamps into UTC to match the database. You want to keep the time-of-day around all through this so that you don’t lose track of what’s going during the timezone transitions.

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

Sidebar

Related Questions

Recently, I learn to develop a rails application. Now, I have a problem. I
I have had this problem w/ two seperate WYSWYG editors in my rails application
I have a problem related to timezone behaviour of a Rails 3.1.1 application. Here
I have inherited a Rails 3 application with a cookie/session problem. Namely, something seems
I'm using Rails 3.1. I'm starting to have a problem -- any time I
I have a Problem in my Rails application. I've left everything at standard Rails
I have a problem with devise 1.1.5 on rails 3.0.3. I have a controller
In my application I have: config.time_zone = 'Warsaw' A strange issue I have, is
I have this problem all the time in my rails apps and I still
I am new to Rails routing and I currently have a problem and hope

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.