i'm very new to spark world . im using spark version 2.3.1. i try to convert string into date format in dataframe i.e "DD-MM-YYYY", however i googled and tried using cast,to_date function its not working . i don't know why .
this is my schema :
b.printSchema
root
|-- Emp: string (nullable = true)
|-- Doj: string (nullable = true)
My data in dataframe:
b.select($"Emp",$"Doj").show()
+---+----------+
|Emp| Doj|
+---+----------+
| a|20-08-2013|
| b|24-05-1945|
| c|13-07-2007|
+---+----------+
what i tried
b.select($"Emp",$"Doj".cast("date")).show()
+---+----+
|Emp| Doj|
+---+----+
| a|null|
| b|null|
| c|null|
+---+----+
b.select($"Emp",to_date($"Doj","format")).show()
+---+------------------------+
|Emp|to_date(`Doj`, 'format')|
+---+------------------------+
| a| null|
| b| null|
| c| null|
+---+------------------------+
why im getting only nulls???