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

# TIMESTAMPDIFF

> Returns complete elapsed units from start to end.

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

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

NULL unit or temporal arguments yield NULL; unknown unit raises an error. Unrepresentable temporal values or overflowing microsecond differences yield NULL.

## Syntax

### Timestampdiff quoted (scalar)

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

* Quote the function name and pass a STRING unit, for example `"timestampdiff"('hour', start, end)`. The unquoted TIMESTAMPDIFF keyword form is rejected.

## Arguments

| 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: NULL unit or temporal arguments yield NULL; unknown unit raises an error. Unrepresentable temporal values or overflowing microsecond differences yield NULL.

## Properties

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

## Units

* Input unit: Temporal values
* Output unit: Specified complete elapsed units

## Usage notes

* Arguments are ordered as (unit, start, end).
* Calendar units use complete units; shorter fixed units truncate incomplete elapsed intervals.

## Examples

### Alias calling form: TIMESTAMPDIFF

* The function name is double-quoted to select its ordinary function-call spelling.

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

| result |
| - |
| 2 |

### Reverse the start and end times

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT "timestampdiff"('hour', TIMESTAMP '2024-03-15 03:00:00', TIMESTAMP '2024-03-15 01:00:00') AS hours;
```

| hours |
| - |
| -2 |

## Limitations

* Use `"timestampdiff"('hour', start, end)` or `TIMESTAMP_DIFF('hour', start, end)`. The unquoted `TIMESTAMPDIFF(HOUR, start, end)` form is rejected.


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