Last Updated : 23 Jul, 2025
The MySQL DATE_SUB() function subtracts a specified time or date interval from a datetime value.
DATE_SUB() Function in MySQLThe DATE_SUB() Function in MySQL allows for various date and time calculations by subtracting time intervals. It is used to subtract a specified time or date interval from a given date and then return the resulting date.
SyntaxMySQL DATE_SUB() function syntax is:
DATE_SUB(date, INTERVAL value addunit)
Parameter:
This function accepts two parameters which are illustrated below :
Let us look at some examples of the DATE_SUB function in MySQL . Learning MySQL DATE_SUB() function with examples will help in understanding it better.
Example 1Getting 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-22Example 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-22Example 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-12Example 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:10Important Points About MySQL DATE_SUB() Function
- The MySQL DATE_SUB() function is used to subtract a specified time or date interval from a given date and then returns the resulting date.
- The DATE_SUB() function is useful for performing date arithmetic, calculating past datetime values, and tracking durations.
- The function can be used with both date and datetime values.
- Related functions include DATE(), LAST_DAY(), DATE_FORMAT(), DATE_ADD(), and DATEDIFF().
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4