我在数据库中有此表
-------------------------------------------------
| id | name | model | inserted_time (timestamp) |
-------------------------------------------------
当我在表中插入内容时,会自动设置 insertted_time ,因此这是当前时间戳。
现在,我需要在表格上进行选择,以使所有条目都比 insertted_time 时间戳早3天。我正在PHP中使用WordPress中的 wpdb 进行此操作。这是我已经拥有的:
$results = $wpdb->get_results( 'SELECT * FROM my_table WHERE inserted_time /*OLDER THEN 3 DAYS */' );
例如,当我关注表中的条目时:
-------------------------------------------------
| id | name | model | inserted_time (timestamp) |
-------------------------------------------------
| 1 | James | xxx | 2018-11-14 21:20:04 |
-------------------------------------------------
所以当我现在选择并且当前时间戳为 2018-11-15 11:20:04 时,我不想在结果对象/数组中输入条目(或其他内容)是)。
但是,当我们拥有当前时间戳时, 2018-11-17 21:20:05 ,我需要在我的结果变量中使用它。
所以我对此深感困惑。我所有与此相关的其他东西都工作正常,但这仍然是一个问题。
是否只能使用SQL做到这一点?还是我需要传递 $ current_timestamp 这样的参数?
答案 0 :(得分:1)
您可以使用now()
或current_timestamp
:
SELECT *
FROM my_table
WHERE inserted_time < now() - interval 3 day;