0
在PostgreSQL中,我需要一種方法來確定當前時間是否在具有opens_at和closes_at時間戳的特定模型的運行時間之內。什麼將是一個有效的Postgres做這件事的方式。只比較postgres中兩個時間戳的時間
對於SQLITE3我:
(opens_at > closes_at AND
(TIME(opens_at) > :now OR :now < TIME(closes_at)))
OR
(closes_at > opens_at AND
(TIME(opens_at) < :now AND TIME(closes_at) > :now))
我忘了說,這是通過ActiveRecord
運行,所以實際上:now
等於當前UTC時間。
將投射到'時間'確保只考慮一天中的時間,**不**日期。我不在乎日期,只是時間。 – OneChillDude
從罰款手冊:[「'時間:一天中的時間(無日期)」](http://www.postgresql.org/docs/current/interactive/datatype-datetime.html#DATATYPE-DATETIME-TABLE) 。 –
你暗戀它。謝謝! – OneChillDude