---
title: datediff function
description: Learn the syntax of the datediff function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/datediff
---

# `datediff` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL preview ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 11.3 LTS and above

Returns the number of days from `startDate` to `endDate`.

## Syntax

```
datediff(endDate, startDate)
```

## Arguments

* `endDate`: A `DATE` expression.
* `startDate`: A `DATE` expression.

## Returns

An `INTEGER`.

If `endDate` is before `startDate` the result is negative.

To measure the difference between two dates in units other than days use [`datediff` (timestamp) function](https://docs.databricks.com/aws/en/sql/language-manual/functions/datediff3.md).

## Examples

```sql
> SELECT datediff('2009-07-31', '2009-07-30');
 1
> SELECT datediff('2009-07-30', '2009-07-31');
 -1
```

## Related functions

* [`date_add` (days) function](https://docs.databricks.com/aws/en/sql/language-manual/functions/date_add.md)
* [`date_sub` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/date_sub.md)
* [`datediff` (timestamp) function](https://docs.databricks.com/aws/en/sql/language-manual/functions/datediff3.md)
