-2

I am trying to extract the year, month and day part of a timestamp column in hive.

At present the output looks like 2016-05-20 01:08:48. I want it to output only the 2016-05-20 part. I have tried using SELECT from_unixtime(unix_timestamp(date,'yyyy-mm-dd')) FROM ANS.test but it hasn't work.

user4157124
  • 2,809
  • 13
  • 27
  • 42
Oye
  • 57
  • 2
  • 7
  • Possible duplicate of [Obtain date from timestamp](https://stackoverflow.com/questions/45291975/obtain-date-from-timestamp) – forpas Jun 05 '19 at 16:37

2 Answers2

0

You need to use the to_date function:

select to_date(date_column) 
from ANS.test 

To get the year, month or day you can use the YEAR(date_column), MONTH(date_column) and DAY(date_column) functions

nacho
  • 5,280
  • 2
  • 25
  • 34
0

I think it may help you: select from_unixtime(unix_timestamp('2016-05-20 01:08:48', "yyyy-MM-dd HH:mm:ss"), 'yyyy-mm-dd');