> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# DATEDIFF

> Returns local date boundaries with two arguments or complete elapsed units with three arguments.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

**Aliases:** [`date_diff`](/query/sql/functions/date-time/date_diff)

Returns NULL if a temporal argument or unit is NULL, or a timestamp cannot be represented by the temporal conversion. An unknown non-NULL unit raises an error.

## Syntax

### Days (scalar)

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
datediff(end, start)
```

### Units (scalar)

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
datediff(unit, start, end)
```

## Arguments

### Days

| Name | Type | Required | Description |
| - | - | - | - |
| end | DATE or TIMESTAMP | Yes | Ending local date or timestamp. |
| start | DATE or TIMESTAMP | Yes | Starting local date or timestamp. |

### Units

| Name | Type | Required | Description |
| - | - | - | - |
| unit | STRING literal | Yes | Complete elapsed unit to count. year, quarter, month, week, day, hour, minute, second, millisecond or microsecond (case-insensitive aliases supported). Must be a constant argument. |
| start | DATE or TIMESTAMP | Yes | Starting timestamp. |
| end | DATE or TIMESTAMP | Yes | Ending timestamp. |

## Returns

* Type: BIGINT
* NULL behavior: Returns NULL if a temporal argument or unit is NULL, or a timestamp cannot be represented by the temporal conversion. An unknown non-NULL unit raises an error.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Exact result | Yes |

## Units

* Input unit: Calendar dates or timestamps
* Output unit: Days for the two-argument form; specified complete units for the three-argument form

## Usage notes

* Two-argument order is (end,start); three-argument order is (unit,start,end).
* Two arguments compare local calendar dates and discard time-of-day; three arguments count complete elapsed units.
* Calendar year/quarter/month results use complete calendar units, not a fixed number of seconds. Negative differences are possible.

## Examples

### Cross a date boundary

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT datediff(TIMESTAMP '2024-07-16 00:01:00', TIMESTAMP '2024-07-15 23:59:00') AS result;
```

| result |
| - |
| 1 |

### Complete elapsed hours

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT datediff('hour', TIMESTAMP '2024-07-15 22:00:00', TIMESTAMP '2024-07-16 00:30:00') AS result;
```

| result |
| - |
| 2 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.