---
title: "date_diff function in Strata | Oplema"
description: "Count the unit boundaries crossed between two dates or timestamps. Write it as date_diff(part, startdate, enddate) in a Strata Formula or Filter."
url: "https://oplema.com/docs/strata/functions/date-diff"
updated: "2026-11-04"
---

# date\_diff

Count the unit boundaries crossed between two dates or timestamps. For example, January 31 to February 1 crosses one month boundary.

## Try an expression

In [Formula](https://oplema.com/docs/strata/prep/formula), enter the expression and set Output type to **BIGINT**.

### Expression

```
date_diff('hour', TIMESTAMP '1992-09-30 23:59:59', TIMESTAMP '1992-10-01 01:58:00')
```

### Result

```
2
```

To use your own data, replace the example values with column names. Keep format strings and other options as written.

Try it live in Formula

Result
| id | result |
| --- | --- |
| 1 | 2 |

## Arguments and types

```
date_diff(part, startdate, enddate)
```

**part**

Text

**startdate**

Date, Time, Timestamp

**enddate**

Date, Time, Timestamp

Supported signatures (4)

```
date_diff(part: VARCHAR, startdate: DATE, enddate: DATE) → BIGINT
date_diff(part: VARCHAR, startdate: TIME, enddate: TIME) → BIGINT
date_diff(part: VARCHAR, startdate: TIMESTAMP WITH TIME ZONE, enddate: TIMESTAMP WITH TIME ZONE) → BIGINT
date_diff(part: VARCHAR, startdate: TIMESTAMP, enddate: TIMESTAMP) → BIGINT
```

The result type can depend on the input types. See DuckDB for the full argument rules.

## Things to know

Use this in a date difference formula, such as the days between two dates. Other tools often call it datediff.

If the first argument is missing, the result is NULL.

## Related functions

[date\_sub

Count the complete units between two dates or timestamps. For example, January 31 to February 1 is zero complete months. Also available as datesub.

](https://oplema.com/docs/strata/functions/date-sub)[age

Calculate the time between two timestamps as an interval, subtracting the second from the first.

](https://oplema.com/docs/strata/functions/age)[date\_add

Move a date or timestamp forward or backward by an interval.

](https://oplema.com/docs/strata/functions/date-add)[date\_trunc

Round a date or timestamp down to the start of a unit such as month or year. Also available as datetrunc.

](https://oplema.com/docs/strata/functions/date-trunc)

[Browse dates & times](https://oplema.com/docs/strata/functions#dates-&-times) [DuckDB documentation](https://duckdb.org/docs/current/sql/functions/timestamp.html#date_diffpart-starttimestamp-endtimestamp)

Function metadata from DuckDB, used under the [MIT license](https://github.com/duckdb/duckdb/blob/v1.5.4/LICENSE).
