我该如何按时间过滤掉?

时间:2014-07-17 15:03:00

标签: ruby-on-rails postgresql activerecord

我的ActiveRecord Foo模型中有一个名为properties的hstore列,其中有一个名为check_for_new_plan_at的密钥,其中包含以下值"2015-07-14T14:51:42+00:00"

如何搜索/过滤此内容。我试过了

Foo.where("(properties -> 'check_for_new_plan_at')::TIME <= ?", Time.now.utc).first

SQL(在Rails控制台中呈现)返回:

SELECT  "foos".* FROM "foos"  WHERE "foos" ((properties -> 'check_for_new_plan_at')::TIME <= '2014-07-17 15:02:42.175381')  ORDER BY "foos"."id" ASC LIMIT 1

返回0结果。我应该对unix时间戳或其他东西进行类型转换,然后比较Time.now.utc.to_i吗?

建议表示赞赏。

1 个答案:

答案 0 :(得分:0)

以iso8601格式使用时间。这将以2015-07-14T14:51:42Z格式打印日期。要打印'+0000',请使用localtime代替utc

Time.now.localtime('+00:00').iso8601
相关问题