Reputation: 821
I was trying to do DatePart date function in SQL. But i am trying to convert in to Spark SQL. Please see the below code for taking hours using the Date Part function.
Select datepart(hour,jou.creationTime)
Any equivalent code in Spark SQL for the above line of code?
Upvotes: 0
Views: 3810
Reputation: 35219
There is and it is called hour
:
import org.apache.spark.sql.functions.hour
df.select(hour($"creationTime"))
To get string you can use date_format
:
import org.apache.spark.sql.functions.date_format
df.select(date_format($"creationTime", "HH"))
Upvotes: 1