3

I am new to HIVE and I need to get the last day of previous month from a table in hive.

SQL equivalent ---

select last_day(add_months(sysdate,-1)) from dual;

I could only get previous day in the internet which is something like

select * 
from table1 
where dt >= from_unixtime(unix_timestamp()-1*60*60*24, 'yyyyMMdd');

could someone please help me with the query?

Thanks Rakesh

Tatiana
  • 1,489
  • 10
  • 19
  • Hi, you can check this question. It is almost the same with yours. http://stackoverflow.com/questions/17548584/find-last-day-of-a-month-in-hive – Canburak Tümer Oct 14 '15 at 11:13
  • Thanks Canburak,, I did something like this ----- date_sub(from_unixtime(UNIX_TIMESTAMP(),'yyyy-MM-dd'), day(from_unixtime(UNIX_TIMESTAMP(),'yyyy-MM-dd'))) – Rakesh Bharadwaj Oct 15 '15 at 13:22

2 Answers2

3

try this

DATE_SUB(FROM_UNIXTIME(UNIX_TIMESTAMP()),DAY(FROM_UNIXTIME(UNIX_TIMESTAMP())))

Total MapReduce CPU Time Spent: 1 seconds 850 msec
OK
2016-03-31
Amrita Sawant
  • 10,403
  • 4
  • 22
  • 26
1
select date_add(current_date,-day(current_date));
4b0
  • 21,981
  • 30
  • 95
  • 142
Deenbandhu
  • 11
  • 1