In this article, you will learn how to calculate total no. of days between two specific dates using the

function in MySQL. **DATEDIFF**

To get a total no. of days between two specific dates, we use the

function of MySQL.**DATEDIFF**

`DATEDIFF( date1, date2 );`

This function takes two parameters:

- Parameter 1: date1 A date/DateTime value
- Parameter 1: date2 A date/DateTime value

Here are some example to calculate the total no. of days between two specific dates using the

function:**DATEDIFF**

**Example 1:** In this Example, We will compare Datetime values with date and time part to calculate the total number of days between two specific dates.

```
-- When used with datetime values, only the date part is used to compare the date.
select datediff('2016-04-14 11:59:00', '2016-04-13 12:00:00') AS 'Total No. of Days Between Two Specific Date';
```

Total No. of Days Between Two Specific Date

------------------------------------------------------------------

1

**Example 2: **In this Example, We will compare only the date part to calculate the total number of days between two specific dates.

```
-- When used with date Part, only the date part is used to compare the date.
SELECT DATEDIFF('2020-02-10', '2019-12-25') AS 'Total No. of Days Between Two Specific Date';
```

Total No. of Days Between Two Specific Date

-----------------------------------------------------------------

47

**Example 3:** In this Example, We will compare parameter 1 with DateTime values and parameter 2 only the date part to calculate the total number of days between two specific dates.

```
-- When We Compare Datetime values and Only with Date Part
SELECT DATEDIFF('2020-02-10 11:41:14', '2019-12-25') AS 'Total No. of Days Between Two Specific Date';
```

Total No. of Days Between Two Specific Date

-----------------------------------------------------------------

47

**Example 4:** In this example, if we pass the smaller date in the first parameter than the second parameter, then this function will return the negative output.

```
-- When First Parameter is smaller than the second Parameter, it returns a negative value
SELECT DATEDIFF('2019-12-31', '2020-02-10') AS 'Total No. of Days Between Two Specific Date';
```

Total No. of Days Between Two Specific Date

----------------------------------------------------------------

-41

I hope this article will help you to understand how to calculate the total no. of days between two specific dates using the **DATEDIFF** function in MySQL.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!

## Comments