snowflake.snowpark.functions.datediff

snowflake.snowpark.functions.datediff(part: str, col1: Union[Column, str], col2: Union[Column, str]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L4206-L4237)

Calculates the difference between two date, time, or timestamp columns based on the date or time part requested, and returns result of col2 - col1 based on the requested date or time part.

Supported date and time parts

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            |
---------------
Copy
Parameters:
  • part – The time part to use for calculating the difference

  • col1 – The first timestamp column or subtrahend in the datediff

  • col2 – The second timestamp column or the minuend in the datediff

语言: 中文