Kohana ORM:如何查询基于数据库中的字段计算的时间戳


Kohana ORM: How to query for a timestamp that's calculated based on a field in the DB

简单表:

start_date       TIMESTAMP
duration_days    INT

用英语:我只想要未超过其duration句点的行。

在 SQL 中:

SELECT * FROM MyTable WHERE now() < TIMESTAMPADD(DAY, duration_days, start_date);

如何在Kohana/ORM中执行此操作?我需要检索的许多行中的每一行的持续时间都不同。

只需使用 where() 子句:

ORM::factory('MyTable')->where(DB::expr('now()'), '<', DB::expr('TIMESTAMPADD(DAY, duration_days, start_date)'))->find_all();