DATE_ADD() FUNCTION in MySQL

DATE_ADD() FUNCTION The MySQL DATE_ADD function gets a date value after adding a certain time/date interval. The various versions of MySQL support the DATE_ADD function, namely, MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0 and MySQL 3.23.

Syntax:

DATE_ADD( date, INTERVAL value unit )

Parameters:

date: It is used to specify the date to which the interval should be added. value: It is used to specify the time/date interval value to be added. unit: It is used to specify the unit type of the interval such as DAY, MONTH, MINUTE, etc.

Example 1:

mysql> SELECT DATE_ADD ('2019-07-05', INTERVAL 5 DAY);

Output:

'2019-07-10'

Explanation:

The desired date interval has been added to the start value of the date.

Example 2:

mysql> SELECT DATE_ADD ('2019-07-05 15:30:20', INTERVAL -15 SECOND);

Output:

'2019-07-05 15:30:05'

Explanation:

The desired time interval has been added to the start value of the date.

Please follow and like us:
Content Protection by DMCA.com