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
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308 | 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)
|