【问题标题】:How do I search for a date field after or before a certain date in Active Record如何在 Active Record 中的某个日期之后或之前搜索日期字段
【发布时间】:2012-07-24 00:59:42
【问题描述】:

我知道我可以使用范围来搜索日期位于两个日期之间的位置。例如:

User.where(:created_at => start_date..end_date )

但是我如何对某个日期之前或之后的所有日期进行开放式搜索?

感谢您的帮助

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-3 activerecord


【解决方案1】:

你可以这么简单:

User.where("created_at >= ?", start_date )

或者这个

User.where("created_at <= ?", end_date )

【讨论】:

    猜你喜欢
    • 2011-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 2021-06-16
    • 1970-01-01
    相关资源
    最近更新 更多