获取当前日期:
方式1:
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss') curr_date;
返回:
2020-09-17 10:42:51
方式2:
CURRENT_DATE
select CURRENT_DATE
返回:
2020-06-05(当前日期)
方式3:
current_date()
select current_date()
返回:
2020-06-05(当前日期)
date_add函数获取后一天日期:
Time taken: 0.074 seconds, Fetched: 1 row(s)
hive (default)> select date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),1);
unix_timestamp(void) is deprecated. Use current_timestamp instead.
OK
_c0
2019-05-31
Time taken: 0.097 seconds, Fetched: 1 row(s)
hive (default)>
date_sub获取前2天和后两天的日期:
方式:1:
select date_sub(CURRENT_DATE,1);
返回:
2020-06-04(当天前一天日期)
方式2:
select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),2)
select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-2)