项目github地址:bitcarmanlee easy-algorithm-interview-and-practice
欢迎大家star,留言,一起学习进步

做数据挖掘的,离不开使用各种时间函数。
为了避免遗忘,以及后续各种抓瞎到处乱找,特意总结了hive中大部分常用的时间函数,方便自己也方便他们。

1.unix_timestamp()

返回当前时区的unix时间戳
返回类型:bigint
hive (tmp)> select unix_timestamp() from hive_sum limit 1;
1465875016

2.from_unixtime(bigint unixtime[,string format])

时间戳转日期函数
返回类型:string
hive (tmp)> select from_unixtime(unix_timestamp(),‘yyyyMMdd’) from hive_sum limit 1;
20160614

3.unix_timestamp(string date)

返回指定日期格式的的时间戳
返回类型:bigint
注意:如果后面只有date参数,date的形式必须为’yyyy-MM-dd HH:mm:ss’的形式。
hive (tmp)> select unix_timestamp(‘2016-06-01’) from hive_sum limit 1;
NULL
hive (tmp)> select unix_timestamp(‘2016-06-01 00:00:00’) from hive_sum limit 1;
1464710400

4.unix_timestamp(string date,string pattern)

返回指定日期格式的时间戳
返回类型:bigint
hive (tmp)> select unix_timestamp(‘2016-06-01’,‘yyyyMMdd’) from hive_sum limit 1;
1449331200

5.to_date(string date)

返回时间字段中的日期部分
返回类型:string
hive (tmp)> select to_date(‘2016-06-01 00:00:00’) from hive_sum limit 1;
2016-06-01

6.year(string date)

返回时间字段中的年
返回类型:int
hive (tmp)> select year(‘2016-06-01 00:00:00’) from hive_sum limit 1;
2016

7.month(string date)

返回时间字段中的月
返回类型:int
hive (tmp)> select month(‘2016-06-01’) from hive_sum limit 1;
6

8.day(string date)

返回时间字段中的天
返回类型:int
hive (tmp)> select day(‘2016-06-01’) from hive_sum limit 1;
1

9.weekofyear(string date)

返回时间字段是本年的第多少周
返回类型:int
hive (tmp)> select weekofyear(‘2016-06-01’) from hive_sum limit 1;
22

10.datediff(string enddate,string begindate)

返回enddate与begindate之间的时间差的天数
返回类型:int
hive (tmp)> select datediff(‘2016-06-01’,‘2016-05-01’) from hive_sum limit 1;
31

11.date_add(string date,int days)

返回date增加days天后的日期
返回类型:string
hive (tmp)> select date_add(‘2016-06-01’,15) from hive_sum limit 1;
2016-06-16

12.date_sub(string date,int days)

返回date减少days天后的日期
返回类型:string
hive (tmp)> select date_sub(‘2016-06-01’,15) from hive_sum limit 1;
2016-05-17

hive 时间函数 总结相关推荐

  1. hive时间函数的使用

    时间函数的变形 selectday -- 时间,date_add(day,1 - dayofweek(day)) as week_first_day -- 本周第一天_周日,date_add(day, ...

  2. hive时间函数入门

    1)当前系统时间函数:current_date().current_timestamp().unix_timestamp() -- 函数1:current_date(); 当前系统日期 格式:&quo ...

  3. hive 时间函数_Hive常用大法(聚合/排序/分组)

    Hello大家好,今天我们继续上篇文章,为大家分享一些Hive在工作中常用的聚合函数,分组函数,排序等等---- 我们就直接从聚合函数开始,什么是聚合函数呢,其实就是一句话,将多行合并为一行,就这么简 ...

  4. Hive时间日期函数一文详解+代码实例

    目录 前言 一.HiveSQL运行过程 二.Hive时间函数 1.获取当前时间 1.current_date() 2. current_timestamp() 3. unix_timestamp() ...

  5. presto 时间函数

    时间函数 0.当前日期/当前时间 presto:adm> select current_date,current_time,current_timestamp[=now()]-> ;_co ...

  6. mediarecorder添加时间戳_Python脚本实现数据处理(官方实例)和Hive自带时间函数...

    官网示例 官网地址: https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-ApacheWebl ...

  7. HIVE获取时间函数, regexp_extract正则提取用法

    Hive获取时间函数 regexp_replace(date_add(from_unixtime(unix_timestamp(), "yyyy-MM-dd") , -1), '- ...

  8. hive 时间转字符串_hive日期函数

    hive的函数有很多,今天我带大家来总结下hive中常用的日期函数吧!!! 如有不足,还请大家多多指出,希望能和大家一起交流,共同进步! 时间一点一滴在溜走,我们要珍惜每一刻 1.日期时间转日期函数: ...

  9. Hive SQL时间函数及用法

    Hive SQL时间函数 当前官方提供的日期函数共27个,内容如下: 1. 获取当前系统时间 函数: current_timestamp 返回值:timestamp 返回查询计算开始时的当前时间戳(从 ...

  10. Hive常用函数大全一览

    Hive常用函数大全一览 1 关系运算 1.1 1.等值比较: = 1.2 2.不等值比较: 1.3 3.小于比较: < 1.4 4.小于等于比较: <= 1.5 5.大于比较: > ...

最新文章

  1. CentOS 安装docker.ce报错提示containerd.io >= 1.2.2-3问题
  2. 《自然语言处理中的因果推理》综述论文,以色列理工谷歌等13位NLP大牛阐述因果推理NLP的估计、预测、解释和超越...
  3. Linux 信号随笔
  4. 【项目实战】mybatis +vue.js 前后端交互批量删除
  5. leetcode贪心算法题集锦(持续更新中)
  6. JDK文档中关于Semaphore的正确使用以及使用场景
  7. hover一个div展示另一个div
  8. MCSE认证全攻略(初、中、高)
  9. java link_Java Link类代码示例
  10. 千万不要错过云计算兴起的时代
  11. IIS6.0系统日志中出现此错误Timer_MinBytesPerSecond,Timer_ConnectionIdle
  12. linux 下tomcat catalina.out日志操作
  13. 【linux】【git】git报错fatal: HTTP request failed
  14. 【Django 2021年最新版教程11】数据库删除操作
  15. 基于JavaWeb的网上订餐网站设计与实现
  16. coap python_一步步搭建物联网系统——RESTful的CoAP协议
  17. CloudMounter一站式网盘管理工具:将大容量网盘服务巧妙地挂载到系统文件管理器中
  18. 计算机视觉实验四-相机标定
  19. 安装mathpix注册不了账户:unexcepted error
  20. 量子计算(一):量子计算是什么

热门文章

  1. day-15 磁盘挂载 磁盘格式化
  2. Android 退出app,后台推送的服务也停止了,怎么可以做到不停止后台服务呢?
  3. 【java】程序初始化顺序
  4. 如何通过nrpe设置Windows 内存检测
  5. 操作数据库为什么需要进行事务控制
  6. Microsoft Excel设置单元格下拉框的方法
  7. C/C++笔记(01):容易出错的几个库函数
  8. Salty Fish(区间和)
  9. $provide.decorator
  10. 实验server2003的域环境里安装一台Server2008 DC