I have a Dataframe with a date
column representing Unix timestamp in String
format. The column values need to be formatted to a different String representation as below -
Input Dataframe
+----+----+-------------+
|name|code| date|
+----+----+-------------+
| A| 1|1545905416000|
| B| 3|1545905416000|
| C| 5|1545905416000|
+----+----+-------------+
Expected output Dataframe
+----+----+-------------+
|name|code| date|
+----+----+-------------+
| A| 1| 2018-12-27|
| B| 3| 2018-12-27|
| C| 5| 2018-12-27|
+----+----+-------------+
This didn't work as it is giving null
for all values -
peopleDFCsv.withColumn("formatted_date",
functions.date_format(functions.col("date"), "yyyy-MM-dd"))
.show();