I am new to hive and sql.
Is there any way to get the current date - 7 in Hive, i.e. the date 7 days ago. And date in my table is in the format 20150910
. (yyyyMMdd
).
I tried below query, but it's not returning anything.
select *
from gmr.tedf_cs_mrch_tran
where cpd_dt = FROM_UNIXTIME(
UNIX_TIMESTAMP(
DATE_SUB(
FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd') , 7 ), 'yyyyMMdd'))
limit 10;
Kindly please help me on this.
You can Use the Condition in where clause :
Here usage_dt is you column name for date, and the DateFormat In Hive used as "yyyy-MM-dd" format so if you are havig any other format you can mention as here yyyyMMdd is the customr format of the sate.
((unix_timestamp(usage_dt,'yyyy-MM-dd')) <= (unix_timestamp(FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd'),'yyyyMMdd'))
There is also alternate option to use DateDiff in where condition like
Hope thses will work for you
Have you tried something like this?