简体   繁体   中英

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.

In SQL:

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

How can I do this in 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM