Skip to content
Related Articles

Related Articles

DATE_SUB() Function in MySQL
  • Last Updated : 03 Dec, 2020

DATE_SUB() function in MySQL is used to subtract a specified time or date interval to a specified date and then returns the date.

Syntax :

DATE_SUB(date, INTERVAL value addunit)

Parameter: This function accepts two parameters which are illustrated below :

  • date – Specified date to be modified
  • value addunit – Here the value is date or time interval to subtract. This value can be both positive and negative. And here the addunit is the type of interval to subtract such as SECOND, MINUTE, HOUR, DAY, YEAR, MONTH etc.

Returns :
It returns the new date after subtraction of specified time or date.

Example-1 :
Getting a new date of “2017-11-22” after the subtraction of 3 year to the specified date “2020-11-22”.



SELECT DATE_SUB("2020-11-22", INTERVAL 3 YEAR);

Output :

2017-11-22

Example-2 :
Getting a new date of “2020-9-22” after the subtraction of 2 month to the specified date “2020-11-22”.

SELECT DATE_SUB("2020-11-22", INTERVAL 2 MONTH);

Output :

2020-09-22

Example-3 :
Getting a new date of “2020-11-12” after the subtraction of 10 days to the specified date “2020-11-22”.

SELECT DATE_SUB("2020-11-22", INTERVAL 10 DAY);

Output :

2020-11-12

Example-4 :
Getting a new date of “2020-11-22 06:12:10” after the subtraction of 3 hours to the specified date “2020-11-22 09:12:10”.

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

Output :

2020-11-22 06:12:10

Example-5 :
Getting a new date of “2020-11-22 09:06:10” after the subtraction of 3 minutes to the specified date “2020-11-22 09:09:10”.

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

Output :

2020-11-22 09:06:10

Example-6 :
Getting a new date of “2020-11-22 09:09:05” after the subtraction of 5 seconds to the specified date “2020-11-22 09:09:10”.

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

Output :

2020-11-22 09:09:05

Application :This function is used to subtract a specified time or date interval to a specified date and then returns the date.

My Personal Notes arrow_drop_up
Recommended Articles
Page :