简体   繁体   English

SQL查询今天是否是数据库日期之前的X天

[英]SQL Query if today is X days before database date

I am using this SQL Query: 我正在使用此SQL查询:

SELECT * from reminders where status <> 'c' AND user = '".$InternalUserResult["sequence"]."' AND duedate_date = '".date("Y-m-d")."' ";

it selects rows from a table based on the status and if the duedate_date is set today 它根据状态以及今天是否设置了duedate_date从表中选择行

i have 3 other columns in the table called duedate_time , remind_user_1 and remind_user_2 我在表中还有3个其他列,分别称为duedate_timeremind_user_1remind_user_2

lets say in this example 在这个例子中可以说

remind_user_1 = 4
remind_user_2 = days

how can i add into my query *if today is 4 days before the due date * 我如何添加到我的查询中*如果今天是截止日期前4天*

and as another example, 再举一个例子

remind_user_1 = 1
remind_user_2 = hour

the query i want to say: 我想说的查询:

if today is 1 hour before the duedate_date + duedatetime

The DATEDIFF function can be used in the where clause. DATEDIFF函数可以在where子句中使用。 In this case, the additional condition looks like: 在这种情况下,附加条件如下:

AND DATEDIFF(duedate_date,CURDATE()) = 4

To get 4 days before date use SUBDATE function in mysql. 要获得日期之前的4天,请在mysql中使用SUBDATE函数。 eg 例如

SELECT SUBDATE(NOW(),4);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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