rails date ranges for same date
Query below works fine when user selects different dates but when user selects same dates like 3/5/2011 and 3/5/2011 it returns nothings. How can i handle this ? If user selects same dates, i want it to find clients which 开发者_高级运维are created at that date.
Client.where(:created_at => date_from..date_to)
You may need to modify your query as below to get between beginning_of_day
and end_of_day
Client.where(:created_at => date_from.beginning_of_day..date_to.end_of_day)
You could create a helper method:
def date_range(from, to)
from == to ? from : from..to
end
Client.where(:created_at=>date_range(date_from,date_to))
精彩评论