snowflake.snowpark.functions.dateadd

snowflake.snowpark.functions.dateadd(part: str, col1: Union[Column, str], col2: Union[Column, str]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.26.0/snowpark-python/src/snowflake/snowpark/functions.py#L5174-L5218)

Adds the specified value for the specified date or time part to date or time expr.

Supported date and time parts

Example:

>>> # add one year on dates
>>> import datetime
>>> date_df = session.create_dataframe([[datetime.date(2020, 1, 1)]], schema=["date_col"])
>>> date_df.select(dateadd("year", lit(1), col("date_col")).alias("year_added")).show()
----------------
|"YEAR_ADDED"  |
----------------
|2021-01-01    |
----------------

>>> date_df.select(dateadd("month", lit(1), col("date_col")).alias("month_added")).show()
-----------------
|"MONTH_ADDED"  |
-----------------
|2020-02-01     |
-----------------

>>> date_df.select(dateadd("day", lit(1), col("date_col")).alias("day_added")).show()
---------------
|"DAY_ADDED"  |
---------------
|2020-01-02   |
---------------
Copy
Parameters:
  • part – The time part to use for the addition

  • col1 – The first timestamp column or addend in the dateadd

  • col2 – The second timestamp column or the addend in the dateadd

Language: English