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

snowflake.snowpark.functions.date_part

snowflake.snowpark.functions.date_part(part: str, e: ColumnOrName) Column[source]

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