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
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353 | 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)
|