Rank in-order of relation to the current date. [Rails, Sqlite3]
How do I return information in rank of closeness t开发者_Python百科o the current date irrelevant of the year. If Current date is May 26 2011, the date closeness to May 26 is returned first. My problem was this confusion: I have two dates: Date 1: May 24th 2011 and Date 2: June 1st 2010, ensuring that Date 2 is returned before Date 1. Both because May 24 has passed and also the year factor.
Table:
Name Created_at
Bob 2010-06-01 (YYYY-MM-DD)
Mike 2010-05-07
Fife 2011-05-09
So it would return if current date is May 26 2011:
Bob 2010-06-01 (YYYY-MM-DD)
Mike 2010-05-07
Fife 2011-05-09
What I have so far:
@awesomeDate = Names.order("name").having("date > ?", Date.today)
精彩评论