impala SQL开发中常用的时间函数,烂笔头一下。。 --获取 当前时间 now() 或者 current_timestamp() --时间戳转换成日期字符串 from_unixtime(bigint unixtime , stringformat ) examples: select from_unixtime(1559318665,'yyyy-mm-dd hh:mm:ss') result: 2019-06-01 00:04:25 --日期转成时间戳 unix_timestamp(string datetime) examples: select unix_timestamp('2019-06-01') result: 1559318400 --日期加减 adddate(timestamp startdate, int days), adddate(timestamp startdate, bigint days) examples: select adddate('2019-06-01',-1) result: 2019-05-31 00:00:00 --加天数 days_add(timestamp startdate, int days) usage: select days_add(now(),2) --减天数 days_sub(timestamp startdate, int days) usage: select days_sub(now(), 2) --月份加减 add_months(timestamp date, int months), add_months(timestamp date, bigint months) examples: select add_months('2019-06-01', 2) result: 2019-08-01 00:00:00.0 --比较两个日期相差天数 datediff(timestamp enddate, timestamp startdate) examples: select datediff('2019-06-01','2019-05-01') result: 31 --得到天,得到月份,得到年 select day(now()) result: 1 select month(now()) result: 6 select year(now()) result: 2019 --得到星期英文 dayname(string date) examples: select dayname("2018-08-05") result:sunday --得到分钟 minute(string date) examples: select minute(now()) --增加分钟 minutes_add(timestamp date, int minutes) examples: select minutes_add(now(),2) --减少分钟 minutes_sub(timestamp date, int minutes) examples: select minutes_sub(now(),2) --得到这周是这年的多少周 weekofyear(string date) examples: select weekofyear('2019-06-01 12:32:54') --得到这一天是这周的第几天 dayofweek(string date) examples: select dayofweek('2019-06-01') result:7 --月份最后一天 last_day(timestamp t) select last_day( '2019-06-01' ) result:2019-06-30 00:00:00 --其他 调度用 --上个月最后一天 select last_day(months_sub(now(),1)) --当月第一天 select days_sub (last_day(months_sub(now(),1)) ,-1)