Returns the number of days between two dates.
Parameters:
| Name | Type | Description | Default |
end | Expression | The end date or timestamp expression. | required |
start | Expression | The start date or timestamp expression. | required |
Returns:
| Name | Type | Description |
Expression | Expression | an Int32 expression with the number of days (end - start). |
Examples:
| >>> import daft
>>> from daft.functions import date_diff
>>> df = daft.from_pydict({"a": ["2021-01-10"], "b": ["2021-01-01"]})
>>> df = df.with_column("a", df["a"].cast(daft.DataType.date()))
>>> df = df.with_column("b", df["b"].cast(daft.DataType.date()))
>>> df = df.with_column("diff", date_diff(df["a"], df["b"]))
>>> df.schema()["diff"].dtype == daft.DataType.int32()
|
Source code in daft/functions/datetime.py
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477 | def date_diff(end: Expression, start: Expression) -> Expression:
"""Returns the number of days between two dates.
Args:
end: The end date or timestamp expression.
start: The start date or timestamp expression.
Returns:
Expression: an Int32 expression with the number of days (end - start).
Examples:
>>> import daft
>>> from daft.functions import date_diff
>>> df = daft.from_pydict({"a": ["2021-01-10"], "b": ["2021-01-01"]})
>>> df = df.with_column("a", df["a"].cast(daft.DataType.date()))
>>> df = df.with_column("b", df["b"].cast(daft.DataType.date()))
>>> df = df.with_column("diff", date_diff(df["a"], df["b"]))
>>> df.schema()["diff"].dtype == daft.DataType.int32()
True
"""
return Expression._call_builtin_scalar_fn("date_diff", end, start)
|