Forum: Ruby on Rails find_by datetime question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ben (Guest)
on 2006-01-03 22:21
(Received via mailing list)
Hi,
  I was wondering if any of you Rails/SQL ninjas knew of an elegant way
 to grab from activerecord all the rows that are within an interval of
the
 current time (say in the last week).  For instance, if there's the
created_on datetime column, is there a zippy way to use find() without
SQL?
 It seems like the Ruby
DateTime object doesn't really do intervals for numerous reasons.

Thanks,
Ben
Rick O. (Guest)
on 2006-01-03 22:24
(Received via mailing list)
On 1/3/06, Ben <removed_email_address@domain.invalid> wrote:
> Hi,
>   I was wondering if any of you Rails/SQL ninjas knew of an elegant way
>  to grab from activerecord all the rows that are within an interval of the
>  current time (say in the last week).  For instance, if there's the
> created_on datetime column, is there a zippy way to use find() without SQL?
>  It seems like the Ruby
> DateTime object doesn't really do intervals for numerous reasons.
>
> Thanks,
> Ben

Look at the time delta stuff that Typo uses:

http://typo.leetsoft.com/trac/browser/trunk/app/mo...

Use it to construct a query like ['created_at BETWEEN ? AND ?', start,
end]


--
rick
http://techno-weenie.net
This topic is locked and can not be replied to.