How can I search date range in Rails with variable date

后端 未结 4 1561
忘掉有多难
忘掉有多难 2020-12-17 16:33

How can I do this in rails active record¿?

find all models that match (created_at + 100 days between this month)

Edit: Ok, Sorry for not be precise this what

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 17:13

    ActiveRecord can build a query using a BETWEEN when it accepts a Range. This sounds like it might be more what you are looking for.

    YourModel.where(created_at: 100.days.ago..100.days.from_now)

    It always seems a little simpler to do this than using >= <= in the query

提交回复
热议问题