snowflake.snowpark.functions.datediff¶
- snowflake.snowpark.functions.datediff(part: str, col1: ColumnOrName, col2: ColumnOrName) Column [source]¶
Calculates the difference between two date, time, or timestamp columns based on the date or time part requested.
Example:
>>> # year difference between two date columns >>> import datetime >>> date_df = session.create_dataframe([[datetime.date(2020, 1, 1), datetime.date(2021, 1, 1)]], schema=["date_col1", "date_col2"]) >>> date_df.select(datediff("year", col("date_col1"), col("date_col2")).alias("year_diff")).show() --------------- |"YEAR_DIFF" | --------------- |1 | ---------------
- Parameters:
part – The time part to use for calculating the difference
col1 – The first timestamp column or minuend in the datediff
col2 – The second timestamp column or the subtrahend in the datediff