A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/sql/date_sub-function-in-mysql/ below:

MySQL DATE_SUB() Function - GeeksforGeeks

MySQL DATE_SUB() Function

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 MySQL

The 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.

Syntax

MySQL DATE_SUB() function syntax is:

DATE_SUB(date, INTERVAL value addunit)

Parameter:

This function accepts two parameters which are illustrated below :

MySQL DATE_SUB() Function Example

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 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
Important Points About MySQL DATE_SUB() Function


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