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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:30:31+00:00 2026-05-24T00:30:31+00:00

I am running in very strange date range query problem. When I use DateTime.now.utc

  • 0

I am running in very strange date range query problem. When I use DateTime.now.utc option to query database, the query date for DateTime.now is different that my current DateTime.now(i.e. one that’s returned on console.)

My mogoid.yml uses-

use_utc: true

I have my named scope like this –

scope :running_auctions, {
       :where => { :end_time.gt => DateTime.now.utc },
       :order_by => [:end_time, "ASC"]
 }

And on console I can do this –

Loading development environment (Rails 3.0.7)

irb(main):001:0> Auction.running_auctions
=> #<Mongoid::Criteria
selector: {:end_time=>{"$gt"=>Fri Jul 22 00:42:38 UTC 2011}},
options:  {:sort=>[:end_time, "ASC"]},
class:    Auction,
embedded: false>

Notice that my date here is Fri Jul 22 00:42:38 UTC 2011

irb(main):002:0> DateTime.now
=> Fri, 22 Jul 2011 11:42:56 +0530

irb(main):003:0> DateTime.now.utc
=> Fri, 22 Jul 2011 06:12:59 +0000

Notice here that my datetime is Fri, 22 Jul 2011 06:12:59 +0000

What is making query date older than actual current date ? Does mogoid or mongodb doing caching there ?
Please let me know if I am missing something.

UPDATE

Loading development environment (Rails 3.0.7)
irb(main):001:0> Auction.running_auctions(DateTime.now.utc)
=> #<Mongoid::Criteria
 selector: {:end_time=>{"$gt"=>Fri Jul 22 01:21:53 UTC 2011}},
 options:  {:sort=>[:end_time, "ASC"]},
 class:    Auction,
 embedded: false>

irb(main):002:0> DateTime.now.utc
=> Fri, 22 Jul 2011 06:52:03 +0000
  • 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-24T00:30:32+00:00Added an answer on May 24, 2026 at 12:30 am

    You have to use a lambda there. As of now, the DateTime.now.utc is computed at application startup and cached with application code.

    You need to write your scope as:

    scope :running_auctions, lambda {
      {
        :where => { :end_time.gt => DateTime.now.utc },
        :order_by => [:end_time, "ASC"]
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got very strange problem. I have one php website which is running in
I'm having a very strange problem. I'm running a loop in a detached thread,
I'm running into a very strange issue that I have found no explanation for
I have a very long-running stored procedure in SQL Server 2005 that I'm trying
Running into a problem where on certain servers we get an error that the
I am stuck onto a very strange situation. I have a workflow that i
I am running into a very strange situation when using the PackageManager.getInstalledPackages() method. The
A very strange thing is happening. I am running a script on a new
The story began with a very strange error while I was running my script
I am fairly proficient in CSS but now I am running into a very

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.