×

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 Create index

An index creation helps to make a row of the table unique. The index operates and handles table data quickly. MySQL index requires NOT NULL column constraint. The index column...

2 minutes read.

MySQL PERIOD_DIFF() function

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

2 minutes read.

MySQL Union

MySQL contains the same categories of data in a different table. Sometimes, you require multiple tables to collect data together. MySQL union is a function to combine two table's data...

5 minutes read.

MySQL AVG function

This function works on numerical data type values. The average function shows the average value of the data set. If an average function returns a null value, then the row...

5 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 HEX() function

In this context, we will learn how we can use the MySQL HEX() function with proper syntax and good examples. Introduction of MySQL HEX() function For returning an equivalent hexadecimal string value...

3 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 Operators

MySQL Operators MySQL operator needs advanced operation on the table and its data. This operator works with the "WHERE" clause. MySQL operators are a statement to modify information. It helps to...

13 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 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 LOAD_FILE() function

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

3 minutes read.

MySQL Stored Procedure

MySQL creates the "stored procedure" function to operate database information. You can use parameters, blocks, and statements to create a new procedure. The procedure requires a database table to use...

3 minutes read.

MySQL Error 1046 - No Database Selected

What is MySQL? MySQL is a Relational Database Management System (RDBMS). SQL in MySQL is the abbreviation of "Structured Query Language", which Oracle developed it in 1995. It is one of...

1 minute read.

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.

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 LIKE() function

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

4 minutes read.

MySQL RADIANS() function

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

2 minutes read.

MySQL ROUND() function

In this context, we will learn how we can use the MySQL ROUND() function with proper syntax and good examples. Introduction of MySQL ROUND() function The ROUND() function in MySQL 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 SUM function

The SUM() function displays the total addition of the table values. It supports the arithmetic operation of the column values. This function does not return a null value. Here, the...

5 minutes read.