ActiveRecord: milliseconds aren't taken into account when using a where clause

不想你离开。 提交于 2019-12-01 05:43:53

Try

Model.where("updated_at > ?", last_update.strftime("%Y-%m-%dT%H:%M:%S.%N%z"))

You can also set this format as the standard format for DateTime in databases by setting (i.e. in an initiallizer):

Time::DATE_FORMATS[:db]= '%Y-%m-%dT%H:%M:%S.%N%z'

then your original query works again:

Model.where("updated_at > ?", last_update)

See the Rails API for DateTime.to_s (aka .to_formated_s)

If you're using the ISO8601 standard you can use .iso8601(10). Don't know why but it rounds to seconds by default.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!