Forum: Ruby on Rails Date Range comparison

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.
2c49cd424ddb3b3c9cef6ef7f45c8534?d=identicon&s=25 Sam Ginko (ginkod)
on 2009-01-19 14:54
I have a set of dates in my database and would like to only get the
latest one or the one closest to the current date. I'm trying to come up
with a way of doing it but had no luck. If any one could help I would
appreciate it.
3cf4a05b544cce274d053d70fd6dc00d?d=identicon&s=25 David Medinets (medined)
on 2009-01-19 16:14
(Received via mailing list)
Sort by date with a limit of one? Hopefully you have an index on that
field?

On Jan 19, 8:54 am, Sam Ginko <rails-mailing-l...@andreas-s.net>
2c49cd424ddb3b3c9cef6ef7f45c8534?d=identicon&s=25 Sam Ginko (ginkod)
on 2009-01-19 16:40
David Medinets wrote:
> Sort by date with a limit of one? Hopefully you have an index on that
> field?
>
> On Jan 19, 8:54�am, Sam Ginko <rails-mailing-l...@andreas-s.net>

forgot to mention that I'm using thinking sphinx as a search engine my
statement looks like this

@allRooms = Room.search :conditions => {:created_at => here is where I
should have a statement}
3be29bee1806b097fc68621eb45f2e37?d=identicon&s=25 Ryan Waldron (rew)
on 2009-01-19 21:15
(Received via mailing list)
You can do this in ActiveRecord is

Room.find :first, :order => 'created_at desc'

See
http://ts.freelancing-gods.com/rdoc/classes/Thinki...
more about ordering search results, which is really what you want.

I don't think the AR flavor I gave above is likely to work out of the
box
with the Sphinx #search method.  However, you could probably just ignore
the
Sphinx part if you really just want the most recently-created record of
your
rooms table, and let AR retrieve it for you.

On Mon, Jan 19, 2009 at 9:40 AM, Sam Ginko
<rails-mailing-list@andreas-s.net
This topic is locked and can not be replied to.