0
votes

I have a table which has month start date as dates . I convert these into quarter using the oracle function trunc(date_column,'q') in oracle. However, this does not work on Hive QL. Need equivalent of this in hive.

Thanks

1

1 Answers

0
votes

This seems to be the cleanest way

with t as (select date '2016-08-27' as dt) 
select add_months(trunc(dt,'MM'),-(month(dt)-1)%3) from t
;

2016-07-01


Here are 2 more options

with t as (select date '2016-08-27' as dt) 
select  trunc(add_months(dt,-(month(dt)-1)%3),'MM') 
from    t
;

2016-07-01


with t as (select date '2016-08-27' as dt) 
select  add_months(trunc(dt,'YY'),cast((month(dt)-1) div 3 * 3 as INT)) 
from    t
;

2016-07-01