Rails ActiveRecord - how to fetch records between two dates

后端 未结 8 1303
执念已碎
执念已碎 2020-12-29 23:16

I have in the database two date columns - from_date and to_date.

Example:

  • from_date: 2012-09-10
8条回答
  •  没有蜡笔的小新
    2020-12-29 23:39

    This should do the trick.

    today = Date.today
    
    data = ModelName.where("from_date <= ? AND to_date >= ?", today, today)
    

提交回复
热议问题