mysql dateadd
时间: 2023-10-23 21:22:19 浏览: 156
MySql Date
MySQL does not have a built-in DATEADD function. Instead, you can use the DATE_ADD function to add a specified interval to a date.
The syntax for DATE_ADD is as follows:
```
DATE_ADD(date, INTERVAL value unit)
```
Here, date is the date to which you want to add the interval, value is the number of units to add, and unit is the type of unit (such as DAY, MONTH, YEAR, HOUR, etc.).
For example, to add one month to the current date, you can use the following query:
```
SELECT DATE_ADD(NOW(), INTERVAL 1 MONTH);
```
This will return the current date plus one month.
You can also use negative values to subtract intervals. For example, to subtract one week from a date, you can use:
```
SELECT DATE_ADD('2021-05-15', INTERVAL -1 WEEK);
```
This will return the date 7 days before May 15, 2021.
阅读全文