Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Format date in HIVE

avatar
Explorer

Hello, how do you format date like this in HIVE ?

from:

Tue Sep 26 22:02:11 CDT 2018

to:

2018-09-26 22:02:11

I've tried different format specifier but didn't work. I must have done something wrong. Any help would be helpful. Thanks

1 ACCEPTED SOLUTION

avatar
Master Guru
@A C

To change the format of the input time we need to use unix_timestamp along with from_unixtime funcitons.

Try with below syntax

hive> select from_unixtime(unix_timestamp("Tue Sep 26 22:02:11 CDT 2018",'EEE MMM dd HH:mm:ss z yyyy'),'yyyy-MM-dd HH:mm:ss');
+----------------------+--+
|         _c0          |
+----------------------+--+
| 2018-09-26 22:02:11  |
+----------------------+--+

-

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.

View solution in original post

1 REPLY 1

avatar
Master Guru
@A C

To change the format of the input time we need to use unix_timestamp along with from_unixtime funcitons.

Try with below syntax

hive> select from_unixtime(unix_timestamp("Tue Sep 26 22:02:11 CDT 2018",'EEE MMM dd HH:mm:ss z yyyy'),'yyyy-MM-dd HH:mm:ss');
+----------------------+--+
|         _c0          |
+----------------------+--+
| 2018-09-26 22:02:11  |
+----------------------+--+

-

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.