Hive时间公式
select
day -- 时间
,date_add(now(), 1 - dayofweek(now())) as week_first_day -- 本周第一天_周日
,date_add(now(), 7 - dayofweek(now())) as week_last_day -- 本周最后一天_周六
,date_add(now(), 1 - case when dayofweek(now()) = 1 then 7 else dayofweek(now()) - 1 end) as week_first_day -- 本周第一天_周一
,date_add(now(), 7 - case when dayofweek(now()) = 1 then 7 else dayofweek(now()) - 1 end) as week_last_day -- 本周最后一天_周日
,next_day(now(), 'TU') as next_tuesday -- 当前日期的下个周二
,trunc(now(), 'MM') as month_first_day -- 当月第一天
,last_day(now()) as month_last_day -- 当月最后一天
,to_date(concat(year(now()),'-',lpad(ceil(month(now())/3) * 3 -2,2,0),'-01')) as season_first_day -- 当季第一天
,last_day(to_date(concat(year(now()),'-',lpad(ceil(month(now())/3) * 3,2,0),'-01'))) as season_last_day -- 当季最后一天
,trunc(now(), 'YY') as year_first_day -- 当年第一天
,last_day(add_months(trunc(now(), 'YY'),12)) as year_last_day -- 当年最后一天
,weekofyear(now()) as weekofyear -- 当年第几周
,second(now()) as second -- 秒钟
,minute(now()) as minute -- 分钟
,hour(now()) as hour -- 小时
,day(now()) as day -- 日期
,month(now()) as month -- 月份
,lpad(ceil(month(now())/3),2,0) as season -- 季度
,year(now()) as year -- 年份
;
标签:dayofweek,last,--,公式,hive,month,时间,now,day
From: https://www.cnblogs.com/dewei233/p/16916355.html