Home >Database >Mysql Tutorial >How to Update DATE Values in MySQL by Adding One Year?

How to Update DATE Values in MySQL by Adding One Year?

DDD
DDDOriginal
2024-11-02 11:50:30251browse

How to Update DATE Values in MySQL by Adding One Year?

Updating DATE Values in MySQL: Adding One Year

When working with date values in MySQL, it's often necessary to perform arithmetic operations such as adding or subtracting a certain period. If you wish to increment a date by one year, the standard approach of using the 1 operator won't suffice.

To effectively update a DATE value and add one year, MySQL provides the DATE_ADD function. Here's the syntax:

UPDATE table SET date = DATE_ADD(date, INTERVAL 1 YEAR)

Let's break down this query:

  • UPDATE table SET date =: This begins the update query, specifying the table and column to be modified.
  • DATE_ADD(date, INTERVAL 1 YEAR): The DATE_ADD function is used to add a specified interval of time to the date column. In this case, we specify an interval of 1 year.

By executing this query, you can easily increment the date values in your MySQL table by one year, allowing for convenient manipulation of date-time data.

The above is the detailed content of How to Update DATE Values in MySQL by Adding One Year?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn