Koushik Chandra
Koushik Chandra

Reputation: 1491

Hive- Extract timestamp and date in defined format

I have column value in my HIVE table in String format like 20160921091213 i.e. YYYYMMDDHHMMDD. In target I have two columns one timestamp and other date column. I want to extract the same in the format for timestamp "YYYY-MM-DD HH24:MI:SS" and for date in the format "YYYY-MM-DD".

What can be the possible SQL for that.

Upvotes: 0

Views: 3220

Answers (1)

nurandi
nurandi

Reputation: 1618

convert to unix timestamp format and then convert back to string.

from_unixtime(unix_timestamp('20160921091213', 'yyyyMMddHHmmss'),'yyyy-MM-dd HH:mm:ss')

Result: 2016-09-21 21:12:13

Upvotes: 1

Related Questions