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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:20:17+00:00 2026-06-01T20:20:17+00:00

I am trying to find events on certain days with this code: Event.where(‘starttime BETWEEN

  • 0

I am trying to find events on certain days with this code:

Event.where('starttime BETWEEN ? AND ?', DateTime.now.beginning_of_day, DateTime.now.end_of_day)

In rails console if I run DateTime.now.beginning_of_day I get exactly what I expect:

Mon, 09 Apr 2012 00:00:00 -0700

I can see where the problem is occurring but looking at the SQL in rails console. Somehow when the date makes it into the SQL query it gets automatically formatted to the wrong date and time.

SELECT "events".* FROM "events" WHERE (starttime BETWEEN '2012-04-09 07:00:00' AND '2012-04-10 06:59:59')

This is giving me results that vary from today until tomorrow, as the sql above says. I can see that when the DateTime.now.beginning_of_day also DateTime.now.end_of_day are being formatted incorrectly once they make it into the sql query. Do I need to be formatting this in a certain way? Any idea why it would go to 7:00 of today and 7:00 of tomorrow?

I don’t know if it makes a difference but I’m using PostgreSQL.

Thanks!

  • 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-01T20:20:18+00:00Added an answer on June 1, 2026 at 8:20 pm

    See: http://railscasts.com/episodes/106-time-zones-in-rails-2-1

    I think the times you’re quoting above are actually the same time, just one is UTC time (you’re on pacific time right?). To fix this you could try setting:

    config.time_zone = “Pacific Time (US & Canada)”

    in your environment.rb

    You could also try:

    DateTime.now.utc.beginning_of_day
    DateTime.now.utc.end_of_day 
    

    so the you’re using UTC as per the DB

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

Sidebar

Related Questions

Been trying to find this online for a while now. I have a SDL_Surface
I'm trying to find a simple example to detect certain key events on the
I'm trying to write an AppleScript to query iCal and find all the events
I'm trying to find the correct event to listen for that will ensure that
I'm trying to find <body onload=function();> and replace it with <body> on onClick event.
I am trying to find out how to allow users to only select certain
I'm trying to find the cumulated duration of some events, 'start' and 'end' field
In Ruby, I'm trying to do the following. def self.stats(since) return Events.find(:all, :select =>
I'm trying to find a good way to bubble events up a class tree
I am trying to find a nice way to find all events of type

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.