---
schema_version: "1"
id: 80db3b65d1d0cacf0438f04dfeae9bc85c205b07db32841679683b18f5c794ad
title: date_diff(datepart, startdate, enddate)
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/concept/bi-saql-functions-timezone-date-diff.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-functions-timezone-date-diff.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 9a4ebd0c1cc3efe7345cca91a2b56a1c1c573b89507523ed0be6e6e19469b21e
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# date_diff(datepart, startdate, enddate)

Returns an integer representing the interval that has elapsed between two dates.

|             |                                                                                                                                                                                                                          |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `datepart`  | The part of the date to use when calculating the difference. Allowed values are:<ul><li>`year`</li><li>`month`</li><li>`quarter`</li><li>`day`</li><li>`week`</li><li>`hour`</li><li>`minute`</li><li>`second`</li></ul> |
| `startdate` | The start date of the interval.                                                                                                                                                                                          |
| `enddate`   | The end date of the interval.                                                                                                                                                                                            |

The difference between two dates is calculated based on the difference in the indicated date parts. For example, the year difference between two dates is calculated by subtracting the year part of `startdate` from the year part of `enddate`.

Suppose `OrderDate` and `ShipDate` are `DateOnly` types. The order date is 31-1-2017 and the ship date is 1-2-2018.

The year difference between the order date and ship date is 1.

```nolang
date_diff("year", 'OrderDate' 'ShipDate');
```

The month difference between the order date and ship date is 2.

```nolang
date_diff("month", 'OrderDate' 'ShipDate');
```

If _`startdate`_ is after `enddate`, the result is a negative integer.

**See Also**

- [date_diff()](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/reference/bi-saql-functions-date-diff.md)
