已知日期

要求日期

语句

结果

本周任意一天

本周一

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. ubuntu 16.04主题美化

    目录 numix图标 Flatabulous主题 参考: Unity-tweak-tool插件 numix图标 sudo apt-add-repository ppa:numix/ppa sudo a ...

  2. CENTOS 6-7的本地YUM源配置

    本文档适合CENTOS 6-7的本地YUM源配置 cd /media cd CentOS_6.8_Final/ cd Packages 创建目录拷贝文件 mkdir /yum cp * /yum 配置 ...

  3. 基于 CentOS 7 搭建 Git服务器

    Git 是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. ⒈安装依赖库和编译工具 1.安装依赖库 yum install -y curl-devel expat-devel ...

  4. Web安全小结之后端

  5. Netty怎么切换三种I/O模式和源码解释

    参考文献:极客时间傅健老师的<Netty源码剖析与实战>Talk is cheap.show me the code! 三种I/O模式 BIO:Block I/O,即同步并阻塞的IO:BI ...

  6. PAT A1036 Boys vs Girls(25)

    AC代码 #include <cstdio> #include <algorithm> using namespace std; const int max_n = 11000 ...

  7. Boot-crm管理系统开发教程(一)

    ps:上周就把这个项目写完了,一直忘记记录,现在补上. Boot-crm是书上第十八章的内容,书上提供了前端的代码,所以只需要写后端的代码就可以了,①所以我们先把前端的代码移植到项目中. ②然后在li ...

  8. IaaS、PaaS、SaaS是云计算的三种服务模式

    IaaS.PaaS.SaaS是云计算的三种服务模式 1. SaaS:Software-as-a-Service(软件即服务)提供给客户的服务是运营商运行在云计算基础设施上的应用程序,用户可以在各种设备 ...

  9. c# 是如何对一个可遍历对象实现遍历的

    public class Persons:IEnumerable { public Persons(string[] people) { this.people = people; } public ...

  10. O043、计算节点宕机了怎么办

    参考https://www.cnblogs.com/CloudMan6/p/5562131.html   Rebuild 可以恢复损坏的instance .那如果是宿主机坏了怎么办呢?比如硬件故障或者 ...