I have date saved in the below format :
+-------------------------+
| timex (varchar) |
+-------------------------+
| 20200303 |
+-------------------------+
I want the output/convert the value into date /time format in Databricks SQL.
Should be :
+-------------------------+
| timex |
+-------------------------+
| 2020-03-03 00:00:00.000 |
+-------------------------+
Tried :
select to_timestamp(timex)--> results in 1970-xx-xxselect to_timestamp(timex, 'yyyy/MM/dd HH:mm:ss.ssssss')--> says datatype in argument 1 should be in string or dateselect to_timestamp(CAST(timex AS STRING), 'yyyy/MM/dd HH:mm:ss.ssssss')--> NULLselect to_date(timex)--> NULL
Equivalent in SQL - convert(datetime,cast(timex as nvarchar),103)
If I use cast(timex as string) as xx --> it works But, i I use to_timestamp(cast(timex as string), 'yyyyMMdd') as t --> it gives null.
I tried to format the string also to_timestamp(format_string('%8d',cast(timex as string)), 'yyyyMMdd') --> getting exception : IllegalFormatConversionException