I need to convert a descriptive date format from a log file "MMM dd, yyyy hh:mm:ss AM/PM" to the spark timestamp datatype. I tried something like below, but it is giving null.
val df = Seq(("Nov 05, 2018 02:46:47 AM"),("Nov 5, 2018 02:46:47 PM")).toDF("times")
df.withColumn("time2",date_format('times,"MMM dd, yyyy HH:mm:ss AM")).show(false)
+------------------------+-----+
|times |time2|
+------------------------+-----+
|Nov 05, 2018 02:46:47 AM|null |
|Nov 5, 2018 02:46:47 PM |null |
+------------------------+-----+
Expected output
+------------------------+----------------------------+
|times |time2 |
+------------------------+-----+----------------------+
|Nov 05, 2018 02:46:47 AM|2018-11-05 02:46:47.000000" |
|Nov 5, 2018 02:46:47 PM |2018-11-05 14:46:47.000000" |
+------------------------+-----+----------------------+
What is the proper format for converting this?. Note that DD may be having leading zeroes.