> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://help.sigmacomputing.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://help.sigmacomputing.com/_mcp/server.

# DateDiff

The **DateDiff** function calculates the time difference between two dates.

## Syntax

`DateDiff(unit, start, end)`

The function has the following arguments:

<dl>
  <dt>
    unit
  </dt>

  <dd>
    Required
  </dd>

  <dd>
    The unit to measure the difference.
  </dd>

  <dd>
    Can be one of “year”, "quarter", “month”, “week”, “day”, “hour”, “minute”, “second”, “millisecond”.
  </dd>

  <dt>
    start
  </dt>

  <dd>
    Required
  </dd>

  <dd>
    The starting date
  </dd>

  <dd>
    Note that the value must be a date. If the column is not in the appropriate format, use the 

    <a href="/docs/date" target="_self">Date</a>

     function on the argument.
  </dd>

  <dt>
    end
  </dt>

  <dd>
    Required
  </dd>

  <dd>
    The ending date
  </dd>

  <dd>
    Note that the value must be a date. If the column is not in the appropriate format, use the 

    <a href="/docs/date" target="_self">Date</a>

     function on the argument.
  </dd>
</dl>

## Notes

* To find the difference, the **start** date is subtracted from the **end** date. If the **end** date precedes the **start** date, the output is a negative integer.
* The **unit** argument does not support columns.
* Sigma rounds the result to the nearest integer.
* If **start** or **end** is `Null`, the function returns `Null`.

## Examples

```
DateDiff("day", Date("2022-01-01"), Date("2023-01-01"))
```

Finds the difference between the dates January 1, 2022 and January 1, 2023, and returns `365`.

```
DateDiff("day", Date("2024-01-01"), Date("2023-01-01"))
```

Finds the difference between the dates January 1, 2024 and January 1, 2023, and returns `-365`.

```
DateDiff("day", Date("2024-01-01"), Null)
```

Returns `Null`.

```
DateDiff(“day”, [Invoice Date], Today())
```

Returns the number of days between the date in the *Invoice Date* column and the current UTC date.

```
DateDiff("year", [Invoice Date], Date("2018-01-01"))
```

Returns the number of years between the date in the *Invoice Date* column and January 1, 2018.

## Related resources

* [Date](/docs/date)
* <a href="https://quickstarts.sigmacomputing.com/guide/common_date_functions/index.html" target="_blank" rel="noopener noreferrer">
    Quickstart: Common date functions and use cases
  </a>