Nair Athul
Nair Athul

Reputation: 821

Is there any equivalent function for taking hours using Date Part in spark sql

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

Answers (1)

Alper t. Turker
Alper t. Turker

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

Related Questions