Support Questions
Find answers, ask questions, and share your expertise

Format date in HIVE

Solved Go to solution

Format date in HIVE

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

Accepted Solutions
Highlighted

Re: Format date in HIVE

Super 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
Highlighted

Re: Format date in HIVE

Super 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