rose
rose

Reputation: 137

hive - Get date in mm/dd/yyyy format

Using Hive, I have date dates in yyyyMMdd format and I need it in 'MM/dd/yyyy' format.

SELECT dt, 
    CAST(SUBSTRING(FROM_UNIXTIME(UNIX_TIMESTAMP(dt, 'MMddyyyy')), 1, 10) AS date) 
FROM timetable

Upvotes: 0

Views: 511

Answers (1)

nobody
nobody

Reputation: 11090

No need for cast and substring.Specify the dateformat for dt in unix_timestamp() and the desired dateformat for from_unixtime()

select 
       dt,
       from_unixtime(unix_timestamp(dt,'yyyyMMdd'),'MM/dd/yyyy') 
from timetable;

Upvotes: 1

Related Questions