开发者

rails date ranges for same date

开发者 https://www.devze.com 2023-03-21 18:23 出处:网络
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 t

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))
0

精彩评论

暂无评论...
验证码 换一张
取 消