Reputation: 95
I am unable to convert the below string to datetime in Hive.
Mon Dec 12 10:55:11 UTC 2016
I have used date_format('Mon Dec 12 10:55:11 UTC 2016','dd-MM-yyyy')
. But I get NULL
as a result.
Any help will be appreciated.
Upvotes: 1
Views: 403
Reputation: 38290
Use unix_timestamp(string date, string pattern)
to convert string in given format to seconds passed from Unix Epoch (1970-01-01 00:00:00 UTC).
Then use from_unixtime()
to convert to required format.
Demo:
Your initial format is 'EEE MMM dd HH:mm:ss z yyyy'
Converting to yyyy-MM-dd HH:mm:ss
(default):
select from_unixtime(unix_timestamp('Mon Dec 12 10:55:11 UTC 2016','EEE MMM dd HH:mm:ss z yyyy'));
Returns:
2016-12-12 10:55:11
Converting to yyyy-MM-dd
:
select from_unixtime(unix_timestamp('Mon Dec 12 10:55:11 UTC 2016','EEE MMM dd HH:mm:ss z yyyy'),'yyyy-MM-dd');
Returns:
2016-12-12
Upvotes: 3