I need to change string into date format 'YYYY-MM-DD'
Input data is
20180716
20180912
like this in string type and need output as
2018-07-16
2018-09-12
spark.sql("""select TO_DATE(CAST(UNIX_TIMESTAMP(MYDAT, 'yyyyMMdd') AS TIMESTAMP)) AS reg_datefrom Table """)
query for above output is
reg_date
null
null
null
null
null
But when I am writing below code its working.
spark.sql("""
SELECT TO_DATE(CAST(UNIX_TIMESTAMP('20180811', 'yyyyMMdd') AS TIMESTAMP)) AS newdate"""
).show()
Output:
+----------+ | newdate| +----------+ |2018-08-11| +----------+
Where I am doing mistake.
select MYDAT,TO_DATE(CAST(UNIX_TIMESTAMP(MYDAT, 'yyyyMMdd') AS TIMESTAMP)) AS reg_date from TableMYDATcolumn in table