# 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()](/docs/analytics/bi-dev-guide-saql/guide/bi-saql-functions-date-diff.md)
