pyspark.sql.functions.minute#
- pyspark.sql.functions.minute(col)[source]#
Extract the minutes of a given timestamp as integer.
New in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- col
Column
or column name target date/timestamp column to work on.
- col
- Returns
Column
minutes part of the timestamp as integer.
See also
Examples
Example 1: Extract the minutes from a string column representing timestamp
>>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([('2015-04-08 13:08:15',), ('2024-10-31 10:09:16',)], ['ts']) >>> df.select("*", sf.typeof('ts'), sf.minute('ts')).show() +-------------------+----------+----------+ | ts|typeof(ts)|minute(ts)| +-------------------+----------+----------+ |2015-04-08 13:08:15| string| 8| |2024-10-31 10:09:16| string| 9| +-------------------+----------+----------+
Example 2: Extract the minutes from a timestamp column
>>> import datetime >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([ ... (datetime.datetime(2015, 4, 8, 13, 8, 15),), ... (datetime.datetime(2024, 10, 31, 10, 9, 16),)], ['ts']) >>> df.select("*", sf.typeof('ts'), sf.minute('ts')).show() +-------------------+----------+----------+ | ts|typeof(ts)|minute(ts)| +-------------------+----------+----------+ |2015-04-08 13:08:15| timestamp| 8| |2024-10-31 10:09:16| timestamp| 9| +-------------------+----------+----------+