加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails activerecord:按日期时间字段查询记录

发布时间:2020-12-17 01:57:51 所属栏目:百科 来源:网络整理
导读:我正在尝试通过字段start_date查询TimeSlot表中的记录,该字段具有类型datetime.这是我到目前为止尝试失败的原因: TimeSlot.where(:start_date = DateTime.new(2010,9,1))TimeSlot.where(:start_date = DateTime.new(2010,1).to_s)TimeSlot.where(:start_dat
我正在尝试通过字段start_date查询TimeSlot表中的记录,该字段具有类型datetime.这是我到目前为止尝试失败的原因:

TimeSlot.where(:start_date => DateTime.new(2010,9,1))

TimeSlot.where(:start_date => DateTime.new(2010,1).to_s)

TimeSlot.where(:start_date => "2010-09-08")

TimeSlot.where(:start_date => "2010-09-08 00:00:00")

我很感激任何帮助.

解决方法

您的查询对我来说很好.

您确定数据库中有匹配的行吗?

要进行调试,请查看logs / development.log文件.

添加:

问题可能是时区.您的查询正在使用服务器的时区.您的数据可以存储在不同的时区.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读