What is DATE_ADD() function in MySQL()
In MySQL, there are many sub-functions that belong to the Date function, DATE_ADD() is one of them, and is used to modify the date. If we want to add days, years, or months in the date we can do so by using the function of DATE_ADD(). The general syntax of using the DATE_ADD():
The explanation of the above syntax is:
- Use the function DATE_ADD() to modify the date or time
- Replace the “date” with the date on which you want to make modifications
- Use the clause of “INTERVAL” which tells the MySQL to add the interval in the provided date according to the given instructions
- Replace the clause “value” with the exact value you want to make changes; it can be negative as well as positive
- Replace the clause “addunit” in which you want to make changes like MONTH, DAY, YEAR
To understand it more clearly, we will consider some examples, we will take a date and make some changes in its month by using a command:
In the above output, we can see that the month has been changed to July instead of November, similarly, we can also change the year by using the DATE_ADD():
The ten years have been advanced predicted using the DATE_ADD(), likewise, if we want to modify the day we can do so using it:
It is to be noted here if no sign is used with the values by default MySQL will consider it with a positive sign and show the results according to the positive sign. The DATE_ADD() function is also applicable on parameters of time, for example, we can modify the minutes using the command:
In the same way, using the below-mentioned command time will be set to 12:00:00:
Also, to add a quarter (adding four consecutive time intervals), run the command:
Conclusion
MySQL is the most popular relational database management system that is used by many website servers to manage their website data. In managing the data of websites, MySQL uses functions that provide great help to users in saving their time. In this post, we have discussed the DATE_ADD() function that belongs to the DATE() built-in function and is used to modify the dates as well as time. We also modified different dates and times using the DATE_ADD() function so that the readers can understand it properly.