Home >Database >Mysql Tutorial >How Can I Increment Dates in MySQL?
Modifying Date Fields in MySQL: Incrementing Date Values
In MySQL, you can easily update numerical fields by incrementing them using syntax like UPDATE table SET number=number 1. However, when it comes to date fields, the process is slightly different.
Adjusting a Date Field by One Year
To add one year to a date field, you can utilize the DATE_ADD function. This function takes two arguments: a date field and a time interval. To increment the date by one year, use an interval of INTERVAL 1 YEAR.
The following query demonstrates this:
UPDATE table SET date = DATE_ADD(date, INTERVAL 1 YEAR)
This query will add one year to the date field in the specified table. Note that the date field should be in a valid date format.
The above is the detailed content of How Can I Increment Dates in MySQL?. For more information, please follow other related articles on the PHP Chinese website!