In a hive table I have bunch of date that are in integer format.
Example
Table
Date
2015051517
2015051518
2015081517
Query
SELECT CAST(date TO INT)
FROM date_table;
How do I get the above example like below?
date
-------------
2015-05 15:17
2015-05 15:18
2015-08 15:17
Thanks in advance!i
Since your date columns are in integer datatype, cast them as string and use Hive's built-in date functions.
Here what you need:
select date_format(from_unixtime(unix_timestamp(cast(your-column as string),'yyyyMMHHmm')),'yyyy-MM HH:mm') from table;
The above code gave me the following results.
2015-05 15:17
2015-05 15:18
2015-08 15:17
Time taken: 0.088 seconds, Fetched: 3 row(s)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.