Editing Date Values in MySQL: Adding One Year
In MySQL, you can directly increment numerical values using the SET number=number 1 syntax. However, working with dates requires a slightly different approach.
Question:
How do I add one year to a date value in a MySQL table?
Answer:
To add one year to a date field, you can utilize the DATE_ADD (or ADDDATE with INTERVAL) function. The syntax for this function is:
UPDATE table SET date = DATE_ADD(date, INTERVAL 1 YEAR)
Here's how it works:
Example:
Consider the following SQL statement:
UPDATE appointments SET appointment_date = DATE_ADD(appointment_date, INTERVAL 1 YEAR)
This statement would add one year to the appointment_date field in the appointments table for all rows that meet the specified conditions (e.g., where appointment_date is later than a certain date).
The above is the detailed content of How to Add One Year to a Date Value in MySQL?. For more information, please follow other related articles on the PHP Chinese website!