已知日期

要求日期

语句

结果

本周任意一天

本周一

select date_sub(next_day('2016-11-29','MO'),7) ;

2016-11-28

本周任意一天

上周一

select date_sub(next_day('2016-11-29','MO'),14) ;

2016-11-21

本周任意一天

本周二

select date_sub(next_day('2016-11-29','MO'),6)

2016-11-29

本周任意一天

上周二

select date_sub(next_day('2016-11-29','MO'),13) ;

2016-11-22

本周任意一天

上周末

select date_sub(next_day('2016-11-29','MO'),8) ;

2016-11-27

本月任意一天

上月末

select date_sub(trunc('2016-11-02','MM'),1);

2016-10-31

本月任意一天

上月初

select trunc(add_months('2016-11-02',-1),'MM')

2016-10-01

本月任意一天

本月初

select trunc('2016-11-02','MM')

2016-11-01

本月任意一天

上上月26

select date_add(add_months(trunc('2016-11-02','MM'),-2),25) ;

2016-09-26

本月任意一天

上月26

select date_add(add_months(trunc('2016-11-02','MM'),-1),25) ;

2016-10-26

当前时间戳

select current_timestamp() ;

2016-11-30 15:18:06.276

当前时间

select current_date() ;

2016-11-30

本季度任意一天

上季度初

case quarter('2016-05-23')

when 1 then concat(year('2016-05-23')-1,'-10-01')

when 2 then concat(year('2016-05-23'),'-01-01')

when 3 then concat(year('2016-05-23'),'-04-01')

when 4 then concat(year('2016-05-23'),'-07-01')

end

add_months(concat(year('2017-02-23'),'-',substr(concat('0',quarter('2017-02-23')*3+1),-2),'-01'),-6)

本季度任意一天

本季度初

case quarter('2016-05-23')

when 1 then concat(year('2016-05-23'),'-01-01')

when 2 then concat(year('2016-05-23'),'-04-01')

when 3 then concat(year('2016-05-23'),'-07-01')

when 4 then concat(year('2016-05-23'),'-10-01')

end

add_months(concat(year('2017-02-23'),'-',substr(concat('0',quarter('2017-02-23')*3+1),-2),'-01'),-3)

 
 
 

hive常用日期函数-模板的更多相关文章

  1. 【hive 日期函数】Hive常用日期函数整理

    1.to_date:日期时间转日期函数 select to_date('2015-04-02 13:34:12');输出:2015-04-02122.from_unixtime:转化unix时间戳到当 ...

  2. Hive中日期函数总结

    --Hive中日期函数总结: --1.时间戳函数 --日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数 select unix_timestamp(); --获得当前时区 ...

  3. SQL常用日期函数

    原文:http://www.cnblogs.com/coconut_zhang/archive/2009/02/02/1382598.html 1. 当前系统日期.时间 select getdate( ...

  4. Hive的日期函数

    1.unix时间戳转时间函数 语法: from_unixtime(bigint unixtime[, string format]) 返回值: string 说明: 转化UNIX时间戳(从1970-0 ...

  5. hive时间日期函数及典型场景应用

    1.hive取得当前日期时间: 1.1) 取得当前日期: select current_date(); 1.2) 取得当前日期时间: select current_timestamp(); 1.3) ...

  6. MySql常用日期函数(转载)

    /*date_add(date,interval expr type)和date_sub(date,interval expr type)执行日期运算. date 是一个 datetime 或date ...

  7. Oracle常用日期函数

    常用的时间格式掩码如下:掩码元素       含义YYYY           四位数年份 (如:2005)     yearYY             二位数年份(如  05) Q         ...

  8. ORACLE 常用日期函数

    1 . add_months(arg1,num) 返回日期arg1加num个月的新日期. select add_months(date'2011-1-1',1) from dual; result:  ...

  9. hiveSQL常用日期函数

    注意 MM,DD,MO,TU 等要大写 Hive 可以在 where 条件中使用 case when 已知日期 要求日期 语句 结果 本周任意一天 本周一 select date_sub(next_d ...

随机推荐

  1. shell sed 替代1

    sed -e '/-DLUA_USE_LINUX/s/-lreadline/-lreadline -lncurses/g' Makefile > tmp mv tmp Makefile 全局换- ...

  2. krpano下全屏后弹窗失效问题解决方法

    原因 krpano 自身的全屏仅全屏自身,以外的html效果将无法显示 解决方法 把全屏按钮换成浏览器自身的全屏效果 解决步骤 vtourskin.xml <layer name="n ...

  3. GIP画图

    世界坐标:相对于winform窗体来说的, 页面坐标:相对于控件的 设置坐标:相对于显示器 获得Graphics对象一般有两种方式: 1.控件.CreateGraphics();//通过该方式创建后要 ...

  4. Spring的四种事务特性,五种隔离级别,七种传播行为

    Spring事务: 什么是事务: 事务逻辑上的一组对数据对操作,组成这些操作的各个逻辑单元,要么一起成功,要么一起失败. 事务特性(4种): 原子性(atomicity):强调事务的不可分割:一致性( ...

  5. Elastic Search中Document的CRUD操作

    一. 新增Document在索引中增加文档.在index中增加document.ES有自动识别机制.如果增加的document对应的index不存在.自动创建,如果index存在,type不存在自动创 ...

  6. docker-Overlay原生网络

    节点1/键值存储:192.168.50.130 :192.168.50.131 1.下载Consul二进制包并启动 wget https://releases.hashicorp.com/consul ...

  7. Asp.net core Identity + identity server + angular + odata + 权限管理

    今天踩了一个坑. 网站发布后看到了一个 error Refused to execute inline script because it violates the following Content ...

  8. Java EE javax.servlet ServletContainerInitializer接口

    ServletContainerInitializer接口 public interface ServletContainerInitializer 一.介绍 该接口,允许在 web 应用程序的启动阶 ...

  9. Spring 基于 AspectJ 的 AOP 开发

    Spring 基于 AspectJ 的 AOP 开发 在 Spring 的 aop 代理方式中, AspectJ 才是主流. 1. AspectJ 简介 AspectJ 是一个基于 java 语言的 ...

  10. JS基础_对象字面量

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...