A RetroSearch Logo

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

Search Query:

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

DATEDIFF() Function in MySQL - GeeksforGeeks

DATEDIFF() Function in MySQL

Last Updated : 23 Jul, 2025

DATEDIFF() function in MySQL is used to return the number of days between two specified date values. 

Syntax:

DATEDIFF(date1, date2)

Parameter: This function accepts two parameters as given below:

Returns :

It returns the number of days between two specified date values.

Example 1 :

Getting the number of days between two specified date values where the date is specified in the format of YYYY-MM-DD. Here the date1 is greater than date2, so the return value is positive.

SELECT DATEDIFF("2020-11-20", "2020-11-1");  

Output :

19

Example 2:

Getting the number of days between two specified date values where the date is specified in the format of YYYY-MM-DD. Here the date1 is less than date2, so the return value is negative.

SELECT DATEDIFF("2020-11-12", "2020-11-19");  

Output:

-7

Example 3:

Getting the number of days between two specified date values where the date is specified in the format of YYYY-MM-DD HH-MM-SS. 

SELECT DATEDIFF("2020-11-20 09:34:21", "2020-11-17 09:34:21");  

Output:

3

Example 4:

Getting the number of days between two specified date values where the date is specified in the format of YYYY-MM-DD HH-MM-SS. Here time value does not matter as date1 and date2 are taken the same but time is different still the output is zero (0).

SELECT DATEDIFF("2020-11-20 09:34:21", "2020-11-20 08:11:23");  

Output:

0



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