我正在尝试查找数据库(PG)中日期在某个月份内的数据点(并且也很想检查年份是否相同)
我已经尝试过:
my_data.where("date.month = ?", Month )
其中“月份”是一个整数(例如来自 Time.new.month),但似乎不起作用...
最佳答案
所以查询将是这样的:
my_data.where("EXTRACT(MONTH FROM date) = ?", month)
关于ruby-on-rails - Rails where 语句与 datetime.month,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35322489/