converting dd-MMM-yy date format in Spark

Viewed 5827

I have a Spark data frame (Scala API) which contains a column called transfer date, the dates are in string format and are in this format 24-JUL-17.

I want to convert it to date string into timestamp. How can I do it?

2 Answers

It can also be done with to_timestamp(date_col, expr)

import org.apache.spark.sql.functions.to_timestamp

val df = date.withColumn("ts", to_timestamp($"transfer date", "dd-MMM-yy"))

Now ts column in df is of timestamp type.

Related