scalacode
scalacode

Reputation: 1106

convert Tue Jul 07 2019 12:30:42 to timestamp scala /spark

I need to transform convert Tue Jul 07 2020 12:30:42 to timestamp with scala for spark. So the expected result will be : 2020-07-07 12:30:42

Any idea, how to make this please ?

Upvotes: 0

Views: 50

Answers (1)

Lamanus
Lamanus

Reputation: 13541

You can use the to_timestamp function.

spark.conf.set("spark.sql.legacy.timeParserPolicy", "LEGACY") <-- Spark 3.0 Only.

df.withColumn("date", to_timestamp('string, "E MMM dd yyyy HH:mm:ss"))
  .show(false)

+------------------------+-------------------+
|string                  |date               |
+------------------------+-------------------+
|Tue Jul 07 2020 12:30:42|2020-07-07 12:30:42|
+------------------------+-------------------+

Upvotes: 1

Related Questions