You are viewing documentation about an older version (1.3.0). View latest version

snowflake.snowpark.functions.dateadd¶

snowflake.snowpark.functions.dateadd(part: str, col1: ColumnOrName, col2: ColumnOrName) → Column[source]¶

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