Find by Date Regardless of Time

I have a datetime field in the database. How do I find records for a
particular date regardless of the time of day?

The method I’m trying does not work… tasks.find(:all, :conditions =>
[“date
== ?”, Date.today])


Joshua S. Martin

CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s),
contains information that may be confidential, protected by the attorney
client or other legal privileges, and or proprietary non public
information.
If you are not an intended recipient of this message or an authorized
assistant to an intended recipient, please notify the sender by replying
to
this message and then delete it from your system. Use, dissemination,
distribution, or reproduction of this message and or any of its
attachments
(if any) by unintended recipients is not authorized and may be unlawful.

On Apr 27, 9:07 pm, Joshua M. [email protected] wrote:

I have a datetime field in the database. How do I find records for a
particular date regardless of the time of day?

you need to search for records where that date column falls in the
appropriate range (ie midnight on that day until midnight on the
following day0

Fred

Ah, I see. Thanks!

On Tue, Apr 27, 2010 at 4:20 PM, Frederick C. <
[email protected]> wrote:

Fred

contains information that may be confidential, protected by the attorney

You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected][email protected]
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Joshua S. Martin

CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s),
contains information that may be confidential, protected by the attorney
client or other legal privileges, and or proprietary non public
information.
If you are not an intended recipient of this message or an authorized
assistant to an intended recipient, please notify the sender by replying
to
this message and then delete it from your system. Use, dissemination,
distribution, or reproduction of this message and or any of its
attachments
(if any) by unintended recipients is not authorized and may be unlawful.

On Apr 27, 2010, at 4:24 PM, Joshua M. wrote:

you need to search for records where that date column falls in the
appropriate range (ie midnight on that day until midnight on the
following day0

Fred

The method I’m trying does not work… tasks.find(:all, :conditions
=> [“date
== ?”, Date.today])

You might also be able to use date functions of your database engine
to simplify the query (although depending on indexing, it may not be
more performant).

tasks.find(:all, :conditions => [‘DATE(date) = ?’, Date.today])

Be careful with a range that entries that happen to fall exactly on
midnight aren’t counted on both the preceding and following days.

-Rob

Rob B.
http://agileconsultingllc.com
[email protected]
http://gaslightsoftware.com
[email protected].invalid

Rob B. wrote:

Be careful with a range that entries that happen to fall exactly on
midnight aren’t counted on both the preceding and following days.

User.find(:all, :conditions => { :created_at =>
(Date.today)…(Date.today + 1) })

SELECT * FROM “users” WHERE (“users”.“created_at” >= ‘2010-04-28’ AND
“users”.“created_at” < ‘2010-04-29’)

On Tue, Apr 27, 2010 at 4:07 PM, Joshua M. [email protected]
wrote:

I have a datetime field in the database. How do I find records for a
particular date regardless of the time of day?

The method I’m trying does not work… tasks.find(:all, :conditions => [“date
== ?”, Date.today])

You might want to look at

http://github.com/radar/by_star

Just discovered this in the past few days.


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs