select * from table where now() > ADDDATE(times,interval 15 day);
select * from table where now() > DATE_ADD(times,interval 15 day);
In actual operation, the query results of these two statements are the same
Reference website
https://www.w3school.com.cn/sql/func_date_add.asp
MySQL DATE_ADD() function
Definition and usage
The DATE_ADD() function adds the specified time interval to the date.
grammar
DATE_ADD(date,INTERVAL expr type)
The date parameter is a valid date expression. The expr parameter is the time interval you wish to add.
The type parameter can have the following values:
Type value |
---|
MICROSECOND |
SECOND |
MINUTE |
HOUR |
DAY |
WEEK |
MONTH |
QUARTER |
YEAR |
SECOND_MICROSECOND |
MINUTE_MICROSECOND |
MINUTE_SECOND |
HOUR_MICROSECOND |
HOUR_SECOND |
HOUR_MINUTE |
DAY_MICROSECOND |
DAY_SECOND |
DAY_MINUTE |
DAY_HOUR |
YEAR_MONTH |
Instance
Suppose we have the following table:
OrderId | ProductName | OrderDate |
---|---|---|
1 | 'Computer' | 2008-12-29 16:25:46.635 |
Now, we want to add 2 days to "OrderDate" so that we can find the payment date.
We use the following SELECT statement:
SELECT OrderId,DATE_ADD(OrderDate,INTERVAL 2 DAY)
AS OrderPayDate
FROM Orders
result:
OrderId | OrderPayDate |
---|---|
1 | 2008-12-31 16:25:46.635 |