[英]Kohana ORM: How to query for a timestamp that's calculated based on a field in the DB
Simple table: 简单表:
start_date TIMESTAMP
duration_days INT
In English: I simply want the rows which have not passed their duration
period. 用英语:我只希望没有超过其
duration
时间的行。
In SQL: 在SQL中:
SELECT * FROM MyTable WHERE now() < TIMESTAMPADD(DAY, duration_days, start_date);
How can I do this in Kohana/ORM? 如何在Kohana / ORM中做到这一点? The duration is different for each of many rows I need to retrieve.
我需要检索的许多行的持续时间都不相同。
只需使用where()
子句:
ORM::factory('MyTable')->where(DB::expr('now()'), '<', DB::expr('TIMESTAMPADD(DAY, duration_days, start_date)'))->find_all();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.