How to convert a string to timestamp with milliseconds in Hive

前端 未结 5 1773
猫巷女王i
猫巷女王i 2021-02-04 11:27

I have a string \'20141014123456789\' which represents a timestamp with milliseconds that I need to convert to a timestamp in Hive (0.13.0) without losing the milliseconds.

5条回答
  •  粉色の甜心
    2021-02-04 11:44

    i had the date field in this form 2015-07-22T09:00:32.956443Z(stored as string). i needed to do some date manipulations. the following command even though little messy worked fine for me:)

    select cast(concat(concat(substr(date_created,1,10),' '),substr(date_created,12,15)) as timestamp) from tablename;
    

    this looks confusing but it is quite easy if you break it down. extracting the date and time with milliseconds and concat a space in between and then concat the whole thing and casting it into timestamp. now this can be used for date or timestamp manipulations.

提交回复
热议问题