gpt4 book ai didi

ruby-on-rails - Rails where 语句与 datetime.month

转载 作者:行者123 更新时间:2023-12-02 04:13:16 26 4
gpt4 key购买 nike

我正在尝试查找数据库(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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com