totn MariaDB Functions

MariaDB: DATEDIFF Function

This MariaDB tutorial explains how to use the MariaDB DATEDIFF function with syntax and examples.

Description

The MariaDB DATEDIFF function returns the difference in days between two date values.

Syntax

The syntax for the DATEDIFF function in MariaDB is:

DATEDIFF( date1, date2 )

Parameters or Arguments

date1 and date2
The two dates to calculate the difference between. The calculation is date1 - date2.

Note

  • Only the date portion of date1 and date2 is used in the DATEDIFF calculation. The time portion of date1 and date2 is ignored.

Applies To

The DATEDIFF function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB DATEDIFF function examples and explore how to use the DATEDIFF function in MariaDB.

For example:

SELECT DATEDIFF('2014-05-19', '2014-05-10');
Result: 9

SELECT DATEDIFF('2014-05-19 12:17:14', '2014-05-10 10:10:08');
Result: 9

SELECT DATEDIFF('2014-05-19 11:41:14', '2014-03-24');
Result: 56

SELECT DATEDIFF('2014-05-15', '2014-04-08');
Result: 37

SELECT DATEDIFF('2014-05-28', '2013-12-31');
Result: 148

SELECT DATEDIFF('2013-12-31', '2014-05-28');
Result: -148

This last DATEDIFF example would display the difference between current system date and '2014-05-19' (current system date is returned by the CURDATE function).

SELECT DATEDIFF(CURDATE(), '2014-05-19');