snowflake.snowpark.functions.date_part

snowflake.snowpark.functions.date_part(part: str, e: Union[Column, str]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.26.0/snowpark-python/src/snowflake/snowpark/functions.py#L5221-L5246)

Extracts the specified date or time part from a date, time, or timestamp. See DATE_PART for details.

Parameters:
  • part – The time part to use for the addition.

  • e – The column expression of a date, time, or timestamp.

Example:

>>> import datetime
>>> df = session.create_dataframe([[datetime.datetime(2023, 1, 1, 1, 1, 1)]], schema=["ts_col"])
>>> df.select(date_part("year", col("ts_col")).alias("year"), date_part("epoch_second", col("ts_col")).alias("epoch_second")).show()
---------------------------
|"YEAR"  |"EPOCH_SECOND"  |
---------------------------
|2023    |1672534861      |
---------------------------
Copy
Language: English