Project github address: bitcarmanlee easy-algorithm-interview-and-practice
welcome everyone to star, leave a message, and learn and progress together
There is a function of timestamp to date in hive sql
from_unixtime(BIGINT unixtime [, STRING format])
The unixtime in it, the input unit is seconds, which is a ten-digit BIGINT. However, the timestamps we use in practice are generally 13-bit to millisecond timestamps. If the timestamp is directly entered into the method, there will be errors.
If it is a 13-bit timestamp, you can use it like this
from_unixtime(cast(timestamp/1000 as bigint)) as xxx_time
timestamp/1000 is a double type, just cast it directly into bigint.
Of course, you can also fill in optional parameters for the date format after the method.