Adds a number of days to a date.
Parameters:
| Name | Type | Description | Default |
expr | Expression | | required |
days | Expression | An integer expression representing the number of days to add. | required |
Returns:
Examples:
| >>> import daft
>>> from daft.functions import date_add
>>> df = daft.from_pydict({"d": ["2021-01-01", "2021-06-15"], "n": [10, 5]})
>>> df = df.with_column("d", df["d"].cast(daft.DataType.date()))
>>> df = df.with_column("result", date_add(df["d"], df["n"]))
>>> df.schema()["result"].dtype == daft.DataType.date()
|
Source code in daft/functions/datetime.py
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427 | def date_add(expr: Expression, days: Expression) -> Expression:
"""Adds a number of days to a date.
Args:
expr: A date expression.
days: An integer expression representing the number of days to add.
Returns:
Expression: a Date expression.
Examples:
>>> import daft
>>> from daft.functions import date_add
>>> df = daft.from_pydict({"d": ["2021-01-01", "2021-06-15"], "n": [10, 5]})
>>> df = df.with_column("d", df["d"].cast(daft.DataType.date()))
>>> df = df.with_column("result", date_add(df["d"], df["n"]))
>>> df.schema()["result"].dtype == daft.DataType.date()
True
"""
return Expression._call_builtin_scalar_fn("date_add", expr, days)
|