title: How to extract hours from datetime in a pyspark dataframe?
body: <p>I have a <code>pyspark</code> dataframe like the following:</p>
  <pre><code>df.show(5)
  
  +----------+
  |   t_start|
  +----------+
  |1506125172|
  |1506488793|
  |1506242331|
  |1506307472|
  |1505613973|
  +----------+
  </code></pre>
  <p>I would like to get the hour and the day of each unix timestamp. This what I am doing:</p>
  <pre><code>df = df.withColumn(&quot;datetime&quot;, F.from_unixtime(&quot;t_start&quot;, &quot;dd/MM/yyyy HH:mm:ss&quot;))
  df = df.withColumn(&quot;hour&quot;, F.date_trunc('hour',F.to_timestamp(&quot;datetime&quot;,&quot;yyyy-MM-dd HH:mm:ss&quot;)))
  df.show(5)
  
  +----------+-------------------+----+
  |   t_start|           datetime|hour|
  +----------+-------------------+----+
  |1506125172|23/09/2017 00:06:12|null|
  |1506488793|27/09/2017 05:06:33|null|
  |1506242331|24/09/2017 08:38:51|null|
  |1506307472|25/09/2017 02:44:32|null|
  |1505613973|17/09/2017 02:06:13|null|
  +----------+-------------------+----+
  </code></pre>
  <p>And I got <code>null</code> in the column <code>hour</code></p>