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

# atoti.date_diff()

### atoti.date\_diff(from\_date, to\_date, /, \*, unit='days')

Return a measure equal to the difference between two dates.

The measure evaluates to `None` if one of the dates is `None`.

* **Parameters:**
  * **from\_date** ( *\_DateConstantOrVariableMeasureConvertible*) – The starting date.
  * **to\_date** ( *\_DateConstantOrVariableMeasureConvertible*) – The end date.
  * **unit** ([*Literal*](https://docs.python.org/3/library/typing.html#typing.Literal) *\[* *'seconds'* *,*  *'minutes'* *,*  *'hours'* *,*  *'days'* *,*  *'weeks'* *,*  *'months'* *,*  *'years'* *]*) – The difference unit.
    Seconds, minutes, and hours are only allowed if the dates contain time information.
* **Return type:**
  *MeasureDefinition*

### Example

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> from datetime import date
>>> df = pd.DataFrame(
...     columns=["From", "To"],
...     data=[
...         (date(2020, 1, 1), date(2020, 1, 2)),
...         (date(2020, 2, 1), date(2020, 2, 21)),
...         (date(2020, 3, 20), None),
...         (date(2020, 5, 15), date(2020, 4, 15)),
...     ],
... )
>>> table = session.read_pandas(
...     df, default_values={"To": None}, table_name="Example"
... )
>>> cube = session.create_cube(table)
>>> l, m = cube.levels, cube.measures
>>> m["To"] = tt.agg.single_value(table["To"])
>>> m["Diff"] = tt.date_diff(l["From"], m["To"])
>>> cube.query(m["To"], m["Diff"], levels=[l["From"]], include_empty_rows=True)
                    To Diff
From
2020-01-01  2020-01-02    1
2020-02-01  2020-02-21   20
2020-03-20
2020-05-15  2020-04-15  -30
```
