I am very much new to scala and help regarding date format. I have a dataframe :
+-----+----------+----------+-----+
| name| startDate| endDate|price|
+-----+----------+----------+-----+
|steak|01/01/1999|01/01/2000| 150|
|steak|02/02/2000|13/01/2000| 180|
| fish|03/03/2000|12/01/2000| 100|
+-----+----------+----------+-----+
I need to convert the enddate column to yyyyMMdd format and need the result like below:
+-----+----------+----------+-----+
| name| startDate| endDate|price|
+-----+----------+----------+-----+
|steak|01/01/1999|20000101 | 150|
|steak|02/02/2000|20000113 | 180|
| fish|03/03/2000|20000112 | 100|
+-----+----------+----------+-----+
I have tried the below code and getting "NULL" in EndDate column
val result = df.withColumn("EndDate",date_format(col("endDate"), "yyyyMMdd")).select("*").show()
Can anyone please help me?