snowflake.snowpark.functions.datediff(part: str, col1: Union[Column, str], col2: Union[Column, str]) Column[source]

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


>>> # year difference between two date columns
>>> import datetime
>>> date_df = session.create_dataframe([[, 1, 1),, 1, 1)]], schema=["date_col1", "date_col2"])
>>>"year", col("date_col1"), col("date_col2")).alias("year_diff")).show()
|1            |
  • 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