我正在尝试访问日期属性。
Meeting.where('date_year BETWEEN ? AND ?', var1, var2)
日期是会议的属性。日期是datetime类,如何在where调用中调用date.year?
感谢
答案 0 :(得分:0)
尝试以下查询
Meeting.where('extract(year from date) BETWEEN ? and ?', var1, var2)
答案 1 :(得分:0)
Meeting.where('date_year BETWEEN ? AND ?', var1.year, var2.year) # or whatever method casts your date/time object to year
(offtopic,但你也可以这样做:
Meeting.where(date_year: var1.year..var2.year)
假设年份为int)