×

MySQL DATE_ADD() function

In this context, we will learn how we can use the MySQL DATE_ADD() function with proper syntax and good examples.

Introduction of MySQL DATE_ADD() function

In MySQL, the DATE_ADD() function is used to add a mentioned time or date interval to a specific date and then return the date.

Syntax of the MySQL DATE_ADD() function

The syntax of the MySQL DATE_ADD() function is given as follows:

DATE_ADD(dateM, INTERVAL value addedunit)

Parameters or arguments used in MySQL DATE_ADD() function:

There are two parameters accepted by the DATE_ADD() function in MySQL, which are given as follows:

DateM: It is the mentioned date to be Modified.

Value addedunit: Here the value parameter is the date or time interval to be added. This value can be both positive and negative. And here, the add-unit is the type of interval to add, such as SECOND, MINUTE, HOUR, DAY, YEAR, MONTH, etc.

Returns:

It will return the new date after the addition of the mentioned time or date.

Application used for DATE_ADD() function:

The DATE_ADD() function can be used in the given below MySQL versions.:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1
  • MySQL 4.0
  • MySQL 3.23

Examples of MySQL DATE_ADD() function:

Now we will look into some MySQL DATE_ADD() function examples and will explore how we can use the DATE_ADD function in MySQL.

Example 1:

In this example, we will get a new date of "2020-11-22" after the addition of 3 years to the specified date "2017-11-22" in MySQL.

SELECT DATE_ADD("2017-11-22", INTERVAL 3 YEAR);

Output:

2020-11-22
1 row in set (0.00 sec)

Example 2:

In this example, we will get a new date of "2020-11-22" after the addition of 2 months to the specified date "2020-9-22" in MySQL.

SELECT DATE_ADD("2020-9-22", INTERVAL 2 MONTH);

Output:

2020-11-22
1 row in set (0.00 sec)

Example 3:

In this example, we will get a new date of "2020-11-22" after the addition of 10 days to the specified date "2020-11-12" in MySQL.

SELECT DATE_ADD("2020-11-12", INTERVAL 10 DAY);

Output:

2020-11-22
1 row in set (0.00 sec)

Example 4:

In this example, we will get a new "2020-11-22 09:12:10" date after adding 3 hours to the specified date "2020-11-22 06:12:10".

SELECT DATE_ADD("2020-11-22 06:12:10", INTERVAL 3 HOUR);

Output:

2020-11-22 09:12:10
1 row in set (0.00 sec)

Example 5:

In this example, we will get a new date of "2020-11-22 09:09:10" after the addition of 3 minutes to the specified date "2020-11-22 09:06:10".

SELECT DATE_ADD("2020-11-22 09:06:10", INTERVAL 3 MINUTE);

Output:

2020-11-22 09:09:10
1 row in set (0.00 sec)

Example 6:

In this example, we will get a new date of "2020-11-22 09:09:10" after the addition of 5 seconds to the specified date "2020-11-22 09:09:5" in MySQL.

SELECT DATE_ADD("2020-11-22 09:09:5", INTERVAL 5 SECOND);

Output:

2020-11-22 09:09:10
1 row in set (0.00 sec)

Application of MySQL DATE_ADD() function:

This function is used to add a mentioned time or date interval to a mentioned date and then return the date.

Summary:

In the above context, we have learned how we can use the DATE_ADD() function in MySQL used to add a mentioned time or date interval to a mentioned date and then return the date.


Related Topics

MySQL Truncate() Function

In this context, we will learn how we can use the MYSQL TRUNCATE function to truncate a number to a mentioned number of decimal places. Syntax of MySQL Truncate Function A number...

2 minutes read.

MySQL Drop Index

Sometimes we have an index that is not required in data operations. In that case, we can use this statement to remove an existing index from the table. We can...

4 minutes read.

MySQL RIGHT() Function

In this context, we will learn how we can use the MySQL RIGHT() Function with proper syntax and good examples. Introduction of MySQL RIGHT() function The RIGHT() function in MySQL is used...

3 minutes read.

MySQL ASIN() Function

In this context we will learn how we can use the ASIN() function in MySQL with proper syntax and good example. Introduction of MySQL ASIN() function The arc sine value of a...

2 minutes read.

MySQL QUARTER() function

In this context, we will learn how we can use the MySQL QUARTER() function with proper syntax and good examples. Introduction of MySQL QUARTER() function The QUARTER() function in MySQL returns the...

3 minutes read.

MySQL Invisible Index

Invisible Index MySQL index decides an option to the availability of the index for the query optimizer. This index shows the visible and invisible options to displays the index column in...

3 minutes read.

MySQL Date and Time function

The date function displays day, year, month, time, and current date. It shows the date and time as per the requirement of the applications. The data either store on the...

8 minutes read.

MySQL variable

The MySQL variable is essential for storing data in the table. The variable declares data with a specific name or label to avoid confusion. This data label is used in...

6 minutes read.

find_in_set() function in MySQL

This Function is used for finding the position of a particular string from the list of strings. For suppose if the specified string is repeated multiple times, then this functions...

4 minutes read.

MySQL SOUNDEX() function

In this context, we will learn how we can use the MySQL SOUNDEX() function with proper syntax and good examples. Introduction of MySQL SOUNDEX() function SOUNDEX() function in MySQL is used to...

3 minutes read.

MySQL Table

Introduction MySQL table is an essential part of the system. MySQL table stores data using index, rows, and columns. It accesses data from the server quickly because of the table—this table...

22 minutes read.

MySQL FORMAT() function

In this context, we will learn how we can use the MySQL FORMAT() function with proper syntax and good examples. Introduction of MySQL FORMAT() function This function in MySQL helps to format...

2 minutes read.

MySQL MONTHNAME() function

In this context, we will learn how we can use the MySQL MONTHNAME() Function with proper syntax and good examples. Introduction of MySQL MONTHNAME() function In MySQL the MONTHNAME() Function is used...

3 minutes read.

MySQL NOW() function

In this context, we will learn how we can use the MySQL NOW() function with proper syntax and good examples. Introduction of MySQL NOW() function Basically, in MySQL, this function is used...

2 minutes read.

MySQL Vs MongoDB

What is MongoDB? MongoDB is a distributed, open-source, cross-platform document-based database which was created to scale and develop applications simply. It was created as a NoSQL database by MongoDB Inc. MongoDB gets...

6 minutes read.

MySQL Constraints

MySQL Constraints Introduction The constraints help to restrict what values should be stored in a table. The constraints provide limitations of the columns or data. This function helps to insert data in...

20 minutes read.

MySQL LOG() function

In this context, we will learn how we can use the MySQL LOG () function with proper syntax and good examples. Introduction of MySQL LOG() function The LOG() function in MySQL is...

3 minutes read.

MySQL Descending Index

Descending Index It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per...

3 minutes read.

MySQL Features

Features of MySQL MySQL is a relational database management system (RDBMS): It is a collection of many programs and makes relations with many other programs. Easy to use MySQL database: MySQL...

2 minutes read.

MySQL RTRIM() function

In this context, we will learn how we can use the MySQL RTRIM() function with proper syntax and good examples. Introduction of MySQL RTRIM() function It is the function in MySQL that...

2 minutes read.