---
title: "date_sub function in Strata | Oplema"
description: "Count the complete units between two dates or timestamps. For example, date_sub('month', DATE '1992-09-15', DATE '1992-11-14') returns 1."
url: "https://oplema.com/docs/strata/functions/date-sub"
updated: "2026-11-04"
---

# 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.

## Try an expression

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

### Expression

```
date_sub('month', DATE '1992-09-15', DATE '1992-11-14')
```

### Result

```
1
```

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 | 1 |

## Arguments and types

```
date_sub(part, startdate, enddate)
```

**part**

Text

**startdate**

Date, Time, Timestamp

**enddate**

Date, Time, Timestamp

Supported signatures (4)

```
date_sub(part: VARCHAR, startdate: DATE, enddate: DATE) → BIGINT
date_sub(part: VARCHAR, startdate: TIME, enddate: TIME) → BIGINT
date_sub(part: VARCHAR, startdate: TIMESTAMP WITH TIME ZONE, enddate: TIMESTAMP WITH TIME ZONE) → BIGINT
date_sub(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

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

## Related functions

[date\_diff

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

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

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

](https://oplema.com/docs/strata/functions/age)[days\_in\_month

Find the number of days in the month containing a date.

](https://oplema.com/docs/strata/functions/days-in-month)[generate\_series

Create a list of values from start to stop, including stop. Start defaults to 0 and step defaults to 1.

](https://oplema.com/docs/strata/functions/generate-series)

[Browse dates & times](https://oplema.com/docs/strata/functions#dates-&-times) [DuckDB documentation](https://duckdb.org/docs/current/sql/functions/date.html#date_subpart-startdate-enddate)

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