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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:30:06+00:00 2026-06-17T16:30:06+00:00

I see in the Active Record docs, you can query for a date using

  • 0

I see in the Active Record docs, you can query for a date using a greater than / less than comparison. However, what if you want to select where date = Date.today or must I query where date is greater than yesterday and less than tomorrow?

As you can see, I’m doing exactly that in the following queries and querying where Date = today returns an empty set

1.9.3p286 :096 > Subscription.where("created_at = ?", Date.today).count
   (0.5ms)  SELECT COUNT(*) FROM `subscriptions` WHERE (created_at = '2013-01-18')
 => 0 

vs.

1.9.3p286 :098 > Subscription.where("expiration_date < ? AND expiration_date > ?", Date.today + 1, Date.today - 1).count
   (0.4ms)  SELECT COUNT(*) FROM `subscriptions` WHERE (expiration_date < '2013-01-19' AND expiration_date > '2013-01-17')
 => 1 

Is this the proper way to query for today’s date or am I missing something?

  • 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-17T16:30:08+00:00Added an answer on June 17, 2026 at 4:30 pm

    I think this is a DUP of this question:

    How to select date from datetime column?

    Subscription.where("DATE(created_at) = ?", Date.today).count
    

    I’m pretty sure this works in MySQL and PostgreSQL, but I’m not sure if it’s a SQL standard.

    Wikipedia seems to think TO_DATE would be the standard:
    http://en.wikipedia.org/wiki/SQL#Date_and_time

    That didn’t work for me in PostgreSQL though.

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

Sidebar

Related Questions

Is there a way to use codeigniters active record system to construct a query
I've got a codeigniter active record query that uses get('table_name')->result(); The output is below,
i am using subsonic 3.0 and active record with a mysql database now everything
I'd like to schedule a delayed job that contains an active record query (or
I am using Active Record and decorate my classes with attributes. I have a
Using rails and active record, is it possible to set the id to a
I don't really plan on using active record or any of the built in
I have recently been using cookie store and I want to transition to active
see fiddle if patient has time slot alloted already then make color yellow using
see fiddle I want to drag the mouse on cell and whatever is under

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.