首页 > 其他分享 >hive时间公式

hive时间公式

时间:2022-11-22 20:34:08浏览次数:42  
标签:dayofweek last -- 公式 hive month 时间 now day

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

相关文章

  • JS前期数组、字符串、时间、定时器、DOM\BOM事件方法等总结
    1.字符串方法        .charAt(对应字符元素下标)——根据下标查找字符串内元素        .charCodeAt(对应字符元素下标)——根据下标查找字符串某元素在u......
  • 时间序列 建模
    https://blog.csdn.net/qq_42818403/article/details/123632502?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7E......
  • Hive 与 HBase 之间的区别和联系
    首先要知道Hive和HBase两者的区别,我们必须要知道两者的作用和在大数据中扮演的角色概念Hive1.Hive是hadoop数据仓库管理工具,严格来说,不是数据库,本身是不存储数据......
  • SQL将时间段拆分为每天
      实现方法如下 SELECT单号,所属人ID,日期数,convert(char(10),DATEADD(dd,number,s.开始日期),120)AS'开始日期',convert(char(10),DATEADD(dd,number,......
  • k8s1.14.1 集群更新证书过期时间
    适用场景部分组件证书检查只有1年时间(即不止kubelet证书),但当前未过期部分老包可能会出现一些master组件证书,或者kubelet证书只有1年的时间,如果检查发现若干证书都是1年,需......
  • 实例065_使用Sleep方法延迟时间
      usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usi......
  • 实例066 如何确定程序的运行时间
      usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usi......
  • NPOI Excel导入:时间格式2022/5/26导入变成26-5月-2022
    //NPOI导入日期格式处理stringmytime=dateStr.Trim();//dateStr为Excel导入的日期值IFormatProviderculture=newCultureInfo("zh-CN",true);......
  • 获取当前时间的前一天 后一天 一周后
    created(){ //取前一天时间 letreTime=this.getDay(-1,7200000); //转化为毫秒 letjugdeTime=Date.parse(reTime); console.log('昨天:',this.getDay(-......
  • NTP 时间同步
    1、对时需要对到什么精度?      一般家用的电脑时钟误差一分钟完全可以接受。集群服务器配合工作一般需要所有的时钟同步在一秒之内。2、和谁同步?    ......