ActiveRecord Find By Year, Day or Month on a Date field

后端 未结 14 1569
傲寒
傲寒 2020-11-27 10:00

I have an ActiveRecord model that has a date attribute. Is it possible to utilize that date attribute to find by Year, Day and Month:

Model.find_by_year(201         


        
14条回答
  •  心在旅途
    2020-11-27 11:01

    I usually use:

    Model.where('extract(month from birthday_column) = ? and extract(day from birthday_column) = ?', Time.now.month, Time.now.day)
    

提交回复
热议问题