搜索

hive时间公式


发布时间: 2022-11-24 22:09:00    浏览次数:43 次

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             -- 年份
;
免责声明 hive时间公式,资源类别:文本, 浏览次数:43 次, 文件大小:-- , 由本站蜘蛛搜索收录2022-11-24 10:09:00。此页面由程序自动采集,只作交流和学习使用,本站不储存任何资源文件,如有侵权内容请联系我们举报删除, 感谢您对本站的支持。 原文链接:https://www.cnblogs.com/dewei233/p/16916355.html