ImpalaSQL日期常用函数
– 取当天
select cast(now() as timestamp)
select from_unixtime(unix_timestamp(),‘yyyyMMdd’) a
– 取当月
select from_unixtime(unix_timestamp(),‘yyyyMM’)
select from_unixtime(unix_timestamp(),‘yyyy-MM’)
select substr(cast(now() as string) , 1,7)
– 取当年
select from_unixtime(unix_timestamp(),‘yyyy’)
select substr(cast(now() as string) , 1,4)
– 取昨天
select date_sub(now(),interval 1 day )
– 现在日期加1天
select days_add(now(),1) a
select date_add(now(),interval 1 day) aa
– 现在日期相减1天
select date_sub(now(), interval 1 days)
select date_sub(now(), interval 1 day)
– 日期相差天数
select datediff(‘2018-08-05’,‘2018-08-03’) a
select datediff(‘2018-12-07 00:00:00.0’,‘2019-06-04 00:00:00.0’) a —179天
select abs( cast( ((unix_timestamp(‘2018-12-07 00:00:00.0’)-unix_timestamp(‘2019-06-04 00:00:00.0’))/86400) as double) ) a
select abs(cast(substr(‘2019-04-0