转:https://blog.csdn.net/qq646748739/article/details/77997276

--Hive中日期函数总结:
--1.时间戳函数
--日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数
select unix_timestamp(); --获得当前时区的UNIX时间戳
select unix_timestamp('2017-09-15 14:23:00'); 
select unix_timestamp('2017-09-15 14:23:00','yyyy-MM-dd HH:mm:ss');
select unix_timestamp('20170915 14:23:00','yyyyMMdd HH:mm:ss');

--时间戳转日期
select from_unixtime(1505456567); 
select from_unixtime(1505456567,'yyyyMMdd'); 
select from_unixtime(1505456567,'yyyy-MM-dd HH:mm:ss'); 
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'); --获取系统当前时间

--2.获取当前日期: current_date
hive> select current_date from dual
2017-09-15

--3.日期时间转日期:to_date(string timestamp) 
hive> select to_date('2017-09-15 11:12:00') from dual;
2017-09-15

--3.获取日期中的年/月/日/时/分/秒/周
with dtime as(select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss') as dt)
select year(dt),month(dt),day(dt),hour(dt),minute(dt),second(dt),weekofyear(dt)
  from dtime
  
--4.计算两个日期之间的天数: datediff
hive> select datediff('2017-09-15','2017-09-01') from dual;  
14

--5.日期增加和减少: date_add/date_sub(string startdate,int days)
hive> select date_add('2017-09-15',1) from dual;    
2017-09-16
hive> select date_sub('2017-09-15',1) from dual;    
2017-09-14

--其他日期函数
查询当前系统时间(包括毫秒数): current_timestamp;  
查询当月第几天: dayofmonth(current_date);
月末: last_day(current_date)
当月第1天: date_sub(current_date,dayofmonth(current_date)-1)

下个月第1天: add_months(date_sub(current_date,dayofmonth(current_date)-1),1)

最新文章

  1. python 批量更改文件名
  2. 解决ASP.NET 自定义报表部署到IIS浏览时出现ASP.NET会话已结束问题
  3. VC++模态对话框和非模态对话框
  4. Oracle中的注释
  5. MVC学习系列——ActionResult扩展
  6. Qt增加webp格式支持
  7. Firebug控制台详解
  8. 关于offsetWidth innerWidth的使用
  9. OpenGL ES 2.0 雾
  10. Watch time
  11. protobuf 原理
  12. Linux显示只显示目录文件
  13. 类设计:设计卖车的4S店
  14. 服务网关基于RPC的用法
  15. 如何检测或判断一个文件或字节流(无BOM)是什么编码类型
  16. elasticsearch 文档资料
  17. Docker Toolbox替换默认docker machine的存储位置
  18. 【洛谷P1060 开心的金明】
  19. Qt 编程指南 2 Hello Designer
  20. 如何监视 Azure 中的虚拟机

热门文章

  1. Learn About Git Bash
  2. select列表遍历和触发事件
  3. unable to find utility "simctl", not a developer tool or in PATH解决方案
  4. 用FTPClient,执行到ftp.storeFile(fileName, inputFile);无反应了
  5. Ubiq:A Scalable and Fault-tolerant Log Processing Infrastructure
  6. GoF的23种设计模式之创建型模式的特点和分类
  7. Java之利用Freemarker模板引擎实现代码生成器,提高效率
  8. C#实现电信短信SMGP协议程序源码
  9. Eclipse集成Git做团队开发:分支管理
  10. 【转载】Windows系统电脑通过命令msinfo32查看系统信息