pyspark.sql.functions.hour

pyspark.sql.functions.hour(col: ColumnOrName) → pyspark.sql.column.Column

Extract the hours of a given date as integer.

Examples

>>> import datetime
>>> df = spark.createDataFrame([(datetime.datetime(2015, 4, 8, 13, 8, 15),)], ['ts'])
>>> df.select(hour('ts').alias('hour')).collect()
[Row(hour=13)]