已知日期

要求日期

语句

结果

本周任意一天

本周一

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. Linux操作系统原理笔记

    在Linux操作系统内核内部,进程是通过一个链表,而且是一个双向链表来管理的. 进程描述符:每一个进程都有其描述符,每一个描述符彼此之间都有关联性的.   双向链表:   一个进程内部可能包含多个线程 ...

  2. Web在线报表设计器使用指南

    市面上的报表工具有很多,虽说功能大同小异,但每一个报表工具都有各自明确的定位,选择最合适的工具,才能达到事半功倍的效果. 本文将要介绍的ActiveReports报表工具,可全面满足 .NET 报表开 ...

  3. ARC100E. Or Plus Max

    题目 好题.没想出解法. 官方题解: 这个解法和 Small Multiple 那道题的解法有异曲同工之妙. 扩展 若把 $\mathsf{or}$ 改成 $\mathsf{and}$ 或者 $\ma ...

  4. 同一台服务器请求easyswoole的一个websocket接口报错

    求助大神啊!file_get_contents报这个错:failed to open stream: Connection timed out换成curl又报这个错:couldn't connect ...

  5. java 序列化和反序列化的底层实现原理

    出处:序列化和反序列化的底层实现原理是什么? 一.基本概念1.什么是序列化和反序列化 (1)Java序列化是指把Java对象转换为字节序列的过程,而Java反序列化是指把字节序列恢复为Java对象的过 ...

  6. Java EE javax.servlet中的ServletConfig接口

    ServletConfig接口 public interface ServletConfig 实现类:GenericServlet.HttpServlet 一.介绍 一个供servlet容器使用配置对 ...

  7. 服务端相关知识学习(三)Zookeeper的配置

    前面两篇文章介绍了Zookeeper是什么和可以干什么,那么接下来我们就实际的接触一下Zookeeper这个东西,看看具体如何使用,有个大体的感受,后面再描述某些地方的时候也能在大脑中有具体的印象.本 ...

  8. css3常用样式

    .box{ //改变轴的方向 flex-direction:column; //两端对齐 justify-content:space-between; //换行 flex-wrap: wrap; // ...

  9. 浅谈WEB中的高并发

    转载:https://www.cnblogs.com/guan-520/p/9575848.html 何谓高并发 高并发指的是:在同时或极短时间内,有大量的请求到达服务端,每个请求都需要服务端耗费资源 ...

  10. 【Swift后台】目录

    背景介绍 环境安装