Home:ALL Converter>Convert String to Timestamp with milliseconds

Convert String to Timestamp with milliseconds

Ask Time:2019-11-17T22:51:02         Author:marie20

Json Formatter

I need to convert a string value to timestamp in Spark SQL while retaining the milliseconds part. The string value is :'2018-05-15 14:12:44.185'. I tried to type-cast it but it truncates the milliseconds part.

select from_unixtime(unix_timestamp('2018-05-15 14:12:44.185', 'yyyy-MM-dd HH:mm:ss.SSS'))

Can anyone please help so that the milliseconds part is also retained in the resulting value ?

Thanks

Author:marie20,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58901701/convert-string-to-timestamp-with-milliseconds
GMB :

You can use function to_timestamp() to convert the string to a timestamp, like:\n\nselect to_timestamp('2018-05-15 14:12:44.185', 'yyyy-MM-dd HH:mm:ss.SSS')\n",
2019-11-17T16:21:14
yy